After using update_all
to update a bunch of records in one query, I would like to refresh one model object of them. I avoid using reload
method, since it doesn’t have to load the data from database. I can assign the new attributes by using assign_attributes
method. But in this way the model object is changed
. For example:
User.where(''
).update_all(column => value)
current_user.assign_attributes(column => value)
current_user.changed?
# => true
I find a workaround by calling clear_attribute_changes
method
current_user.assign_attributes(column => value)
current_user.send(:clear_attribute_changes, column)
current_user.changed?
# => false
It’s ugly, I think it will be cleaner if we have a assign_attributes_without_changes
method.
current_user.assign_attributes_without_changes(column => value)
current_user.changed?
# => false