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

Eager_loads two different relations, which classes inherited from another one class.

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.1.0
    • Component/s: None
    • Labels:
      None

      Description

      Maybe it's a bug or a feature. When eager_loads by 'includes' two different relations, which classes inherited from another one class, expect two different objects.

      Example:

      class A
        include Mongoid::Document
      end
       
      class B < A
        belongs_to :d
      end
       
      class C < A
        belongs_to :d
      end
       
      class D
        include Mongoid::Document
       
        has_one :b
        has_one :c
      end
       
      d = D.create
      B.create(d: d)
      C.create(d: d)
       
      d = D.includes(:b, :c).first
      d.b == d.c # true
      d.b
      # #<C:0x007fd42aa3d418> {
      #      :_id => "50e5bbf798663904ca000004",
      #    :_type => "C",
      #     :d_id => "50e5bbf798663904ca000002"
      # }
      d.c
      # #<C:0x007fd42aa3d418> {
      #      :_id => "50e5bbf798663904ca000004",
      #    :_type => "C",
      #     :d_id => "50e5bbf798663904ca000002"
      # }
      

      Same behavior with 'has_many' relations.
      Check on Mongoid 3.0.17 and master branch.
      I would appreciate additions and corrections.

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved: