update_attribute verifies "readonly" #7679

Closed
VadimPushtaev opened this Issue Sep 18, 2012 · 1 comment

Projects

None yet

2 participants

@VadimPushtaev
# Updates a single attribute and saves the record.
# This is especially useful for boolean flags on existing records. Also note that
#
# * Validation is skipped.
# * Callbacks are invoked.
# * updated_at/updated_on column is updated if that column is available.
# * Updates all the attributes that are dirty in this object.
#
def update_attribute(name, value)
  name = name.to_s
  verify_readonly_attribute(name)
  send("#{name}=", value)
  save(:validate => false)
end

https://github.com/rails/rails/blob/master/activerecord/lib/active_record/persistence.rb#L168

Is it ok that "readonly" is verified as long as "Validation is skipped"? It looks pretty weird.

@steveklabnik
Member

It may or may not be weird, but it's certainly not a bug.

If you'd like to change this behavior in Rails, please send a pull request removing that line, with all tests passing, and we can discuss the change there. As it stands, this is a feature request, which we don't accept on the Issues tracker. If you'd like to ask questions about this behavior, please email rails-core. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment