-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
With ActiveRecord, you can override attribute= and it will be called for anything other than write_attribute to set the field. I need this behavior, but it is not happening in Mongoid 3.1.4.
I have:
field :is_primary, type: Boolean, default: false
def is_primary=(bool)
disable_others if bool
super(bool)
end
When I call update_attribute(:is_primary, true) the value is updated in the database, but my function is never called so disable_others is never called.
It appears this is caused by update_attribute calling write_attribute(name, value) instead of {{send("#
{name}=", value)}}. See ActiveRecord::Persistence#update_attribute