1 2 3 4 5 6 7 8 9 10
article = Article.find(:first) article.title #=> "Title" article.subject #=> "Edge Rails" # Update one of the attributes article.title = "New Title" # And only that updated attribute is persisted to the db article.save #=> "UPDATE articles SET title = 'New Title' WHERE id = 1"
updated_at/on magic fields will only be set if there are unsaved attributes that need persisting. If there are no changed attributes for the object being persisted then there won’t be any SQL updates made.
To disable this functionality, set
partial_updates = false for each model you wish to not take advantage of partial updates. To disable this system-wide add this line to your
environment.rb or, better yet, in a
ActiveRecord::Base.partial_updates = false
Note: There’s currently a
config/initializers/new_rails_defaults.rb file that has this setting, so edit that file if you have it.