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

Setting has_many to [] only updating *one* child document?

    • Type: Icon: Task Task
    • Resolution: Done
    • 3.0.12
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      Using v3.0.11, it seems like when I set a has_many association to [] only one of the child documents (with the belongs_to) gets its fk nullified:

      class Foo
        include Mongoid::Document
        has_many :bars
      end
      
      class Bar
        include Mongoid::Document
        belongs_to :foo
      end
      
      bars = 2.times.map { Bar.create! }
      foo = Foo.create! :bars => bars
      foo.bars = []
      foo.bars(true)
       => [#<Bar _id: 5097894b0bed3f764600000f, _type: nil, foo_id: "5097894f0bed3f7646000010">]
      Bar.all.map(&:foo_id)
       => [nil, "5097894f0bed3f7646000010"] 
      

      Seems like maybe a :multi => true is missing from an update somewhere..? Seems like quite a critical bug, unless I'm missing something...

            Assignee:
            Unassigned Unassigned
            Reporter:
            bensymonds Ben Symonds
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: