Reputation: 605
There is update_all method in RoR
And what does it return if it update_all fails? will it raise an exception?
For example:
ActiveRecord::Base.transaction do
users = User.active
users.update_all avatar: 'blablablb'
end
Upvotes: 18
Views: 9649
Reputation: 11235
update_all
is one of many methods that skip validations and callbacks. So any ActiveRecord validations simply won't be run when calling update_all
.
However, if the update_all
call doesn't conform to a constraint at the database level, or otherwise triggers an exception in your database, then ActiveRecord will throw a ActiveRecord::StatementInvalid
exception and will break from the update_all
without returning a value, like any other exception.
Other ActiveRecord methods that skip validations include:
Upvotes: 23