-
Type: Bug
-
Resolution: Cannot Reproduce
-
Priority: Minor - P4
-
Affects Version/s: 5.1.0
-
Component/s: None
-
Environment:ruby 2.2.2
rails 4.2.5.2
mongoid 5.1.0
Hi, guys
I have a small issue related with eager loading, I got error during eager loading.
Here are my models, CourseActivity inherit Activity, so I assume CourseActivity inherit 'belongs_to :group' relationship from Activity.
class Activity belongs_to :group end class CourseActivity < Activity has_one :assignment end class Group has_many :activities, class_name: 'Activity' end class Assignment belongs_to :course_activity end # failed with eager loader CourseActivity.includes(:group, :assignment).to_a.count # undefined method `assignment' for #<Group:0x007fbec6b2a020>
However if I add 'belongs_to :group' relationship in CourseActivity, eager loading works fine
class CourseActivity < Activity
belongs_to :group
has_one :assignment
end
# works perfect
CourseActivity.includes(:group, :assignment).to_a.count
I also enable preload_models in mongoid
#mongoid.yml
preload_models: true
I don't know that is caused by polymorphism belongs_to, since found on website "Eager loaded is supported on all relations with the exception of polymorphic belongs_to associations."