Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-3075

update_attribute does not call attribute=

    XMLWordPrintable

    Details

      Description

      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

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: