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

Embedded Associations inside submodules cannot find inverses

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • None

      When you have Models inside modules: 

      module EmmSpec
        class Car
          include Mongoid::Document
          embeds_many :doors
        end
      
        class Door
          include Mongoid::Document
          embedded_in :car
        end
      end

      The inverse association is not calculated correctly:

      door._association.inverse_association # nil 

      This has to do with how we calculate the inverse. One of the conditions for a class being the inverse is:

      rel.relation_class_name.sub(/\A::/, '') == inverse_class_name 

      However here, rel.relation_class_name is "Car" while the inverse_class_name is  "EmmSpec::Car".

      Also include a test for the following case:
      > On embedded relations with touch: true, there is strange behavior the parent accessor on a child document (i.e. for A and B where A is the parent of B, b.a is nil) which is causing the touch not to persist on the parent.

      which is caused by this issue.

            Assignee:
            Unassigned Unassigned
            Reporter:
            neil.shweky@mongodb.com Neil Shweky (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: