I want to change the status of few records in a database in the transaction, so I need to throw an exception when the error occurs. Code below is simplified but shows the problem
User.products.update(status: :vip) # it update but of didn't throw exception
Following update documentation i tried update!
method but it does not work
User.products.update!(status: :vip)
# NoMethodError: undefined method `update!' for #<Product::ActiveRecord_Associations_CollectionProxy:0x00000005463b60
How to use update!
method with collection? Should I iterate over all records, and call update! on each record?