[Feature][ActiveRecord] Add a method to assign attributes without changes

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[Feature][ActiveRecord] Add a method to assign attributes without changes

Khiav REOY

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

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.