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

"changed" in before_save does not reflect HABTM association changes

    • Type: Icon: Bug Bug
    • Resolution: Won't Do
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: Associations, Callbacks
    • Labels:
      None

      Hey,

      I have the following model

      class Person
        include Mongoid::Document
        store_in collection: :persons
        has_and_belongs_to_many :products
      
        #hook before document is saved
        before_save do |document|
          puts changed.inspect
        end
      end

      When i do

      person.products.push(product)
      person.save

      The "changed.inspect" results in an empty Hash
      []
      Where i expect to see ["product_ids"]

      person.products.delete(product)
      person.save

      In this case the "changed.inspect" results in
      ["product_ids"]

      All documents are saved correctly and we use version 4.0.0.beta1

            Assignee:
            neil.shweky@mongodb.com Neil Shweky (Inactive)
            Reporter:
            SanderSander SanderSander [X]
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: