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

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Done
    • 2.1.9
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • 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
              Reporter:
              aanand
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved: