-
Type: Bug
-
Resolution: Gone away
-
Priority: Minor - P4
-
None
-
Affects Version/s: 7.1.2
-
Component/s: Attributes
-
None
-
Environment:rails 5.2, mongoid 7.1, mongo 4.2
I have two models with has_many and belongs_to defined. The following two queries always produce exactly n+1 queries
A.where(:ids.in => ids).includes(:bs).collect{|x| x.bs.count}
A.where(:ids.in => ids).collect{|x| x.bs.count}
The includes has no effect. Here are the specific relations:
class Case
has_many :case_statuses, dependent: :destroy
...
class CaseStatus
belongs_to :case, index: true, inverse_of: :case_statuses
And given an array of ids, ids (in this case there are 10 ids), both queries produce exaclty 11 mongo queries:
Case.where(:id.in => ids).includes(:case_statuses).collect{|x| x.case_statuses.count}
Case.where(:id.in => ids).collect{|x| x.case_statuses.count}
i.e. includes does not reduce the fired mongo queries from 11 to 1 as expected.
Thanks for any help,
kevin