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

Using modules breaks inverse_association of embeds

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

      More module-related issues. It seems that calling `child._association.inverse_association` on a class with a Module is broken. It seems to work if we do the classes in the root namespace.

      # WITH MODULE - inverse_association BROKEN
      
      module Bad
        class Parent
          include Mongoid::Document
          embeds_many :kids
        end
      
        class Kid
          include Mongoid::Document
          embedded_in :parent
        end
      end
      
      parent = Bad::Parent.create!
      kid = parent.kids.create!
      
      kid._association.inverse_class #=> Bad::Parent - OK
      kid._association.inverse_association #=> nil - Expected to the the parent instance
      
      
      # WITHOUT MODULE - WORK FINE
      
      class Parent
        include Mongoid::Document
        embeds_many :kids
      end
      
      class Kid
        include Mongoid::Document
        embedded_in :parent
      end
      
      parent = Parent.create!
      kid = parent.kids.create!
      
      kid._association.inverse_class #=> Parent - OK
      kid._association.inverse_association #=> <Parent> - OK
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            shields@tablecheck.com Johnny Shields
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: