Yes, I believe this is consistent behavior because this instance of the model you just created was not reloaded. Therefore, the βchangedβ attributes were not reset.
Sorry if this is not a very clear explanation. To demonstrate, run the debugger in the after_create method. For instance.
def my_after_save_callback require 'ruby-debug'; debugger update_attribute(:foo, "bar") end
Then, when the debugger starts:
p self.changed
An array of all the attributes that have been changed for this object will be returned. ActiveRecord will update all of these attributes the next time the object is saved.
One way is to reload the object before updating the attribute.
def my_after_save_callback reload update_attribute(:foo, "bar") end
This will reset the βchangedβ attributes, and only the specific attribute that you change will be updated in the SQL query.
Hope that makes sense :-)
source share