-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
-
None
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.