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
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With