There is no way to do this, here is the code for update_attributes
(which is an alias for update
)
def update(attributes) with_transaction_returning_status do assign_attributes(attributes) save end end
As you can see, it simply assigns the given attributes and saves without passing any argument to the save
method.
These operations are enclosed in a block passed to with_transaction_returning_status
to prevent problems when some assignments modify data in associations. Thus, you are safer to enable these operations when called manually.
One simple trick is to add a context sensitive public method to your model as follows:
def strict_update(attributes) with_transaction_returning_status do assign_attributes(attributes) save(context: :strict) end end
You can improve it by adding update_with_context
directly to your ApplicationRecord
(the base class for all models in Rails 5). So your code will look like this:
class ApplicationRecord < ActiveRecord::Base self.abstract_class = true
source share