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

dependent does not cascade

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 7.0.2
    • Component/s: Associations

      Say I have three classes set up with has_many associations that form a chain:

      class C
        include Mongoid::Document
        belongs_to :b, optional: true
      end
      
      class B
        include Mongoid::Document
        has_many :cs, class_name: "C", inverse_of: :b, dependent: :nullify
        belongs_to :a, optional: true
      end
      
      class A
        include Mongoid::Document
        has_many :bs, class_name: "B", inverse_of: :a, dependent: :destroy
      end
      

      When I now create a chain of objects:

      a = A.create
      b = a.bs.create
      c = b.cs.create
      

      And clear the bs in a, I'd expect c's b_id to be nullified, however:

      a.bs.clear # => {}
      b.reload # throws an exception as expected
      c.reload
      c.b_id # => BSON::ObjectId('5c5f0e6d77b4b61dc25376c8')
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            sven.riedel@givve.com Sven Riedel
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: