update_attribute does not call attribute=

XMLWordPrintableJSON

    • None
    • None
    • None
    • None
    • None
    • None
    • 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

              Assignee:
              Durran Jordan
              Reporter:
              Nuru [X]
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved: