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

Setting a.parent = b in a same-class referenced_in association sets b.parent to a

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

      Best explained with a spec:

      
      require "spec_helper"
      
      describe "A same-class referenced_in association" do
        before do
          class Foo
            include Mongoid::Document
            referenced_in :parent, class_name: "Foo"
          end
        end
      
        context "setting `a.parent = b'" do
          let(:a) { Foo.new }
          let(:b) { Foo.new }
      
          before do
            a.parent = b
          end
      
          it "sets a.parent" do
            a.parent.should == b
          end
      
          it "does not set b.parent" do
            b.parent.should be_nil
          end
        end
      end
      

      The second example fails: b.parent is set to a.

            Assignee:
            Unassigned Unassigned
            Reporter:
            aanand aanand
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: