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

Setting referenced-in relation breaks substitution of the inverse relation.

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 7.0.0
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      Since commit 5a1f8f3b5256af3cfb3d3fc99737c37a3660591e (RE: MONGOID-2943), binding of a referenced-in relation no longer works right, because the inverse relation is set to the document itself rather than a relation proxy wrapping it:

      class Parent
        include Mongoid::Document
      
        has_one :child, inverse_of: :parent
      end
      
      class Child
        include Mongoid::Document
      
        belongs_to :parent, inverse_of: :child
      end
      
      parent = Parent.new
      child = Child.new
      
      child.parent = parent
      
      parent.child = nil # or parent.child = Child.new — same thing happens
      # => NoMethodError: undefined method `substitute' for #<Child:0x007f92b6a52be8>
      

      I've reverted the commit in my own fork, but obviously that's not a good solution as it returns the extra query on has_one relations.

      /cc arthurnn

            Assignee:
            emily.stolfo Emily Stolfo
            Reporter:
            DouweM Douwe Maan [X]
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: