ActiveRecord #update saves modified attributes not part of the attributes parameter


I’m surprised by the following behavior (reproduced both in Rails 7.1 and 6.1):

u = User.first
u.first_name = 'Joe'
u.update last_name: 'Doe'
# both first_name and last_name are updated in the DB, not only last_name

I was not expecting first_name to be updated in the DB.

I think at least it should be mentioned in the official documentation update (ActiveRecord::Base) - APIdock and Active Record Basics — Ruby on Rails Guides.


I agree, that is certainly not the behaviour I’d expect. I imagine this is just something that rarely comes up due to convention.