mysql - Active Record: eager_load performs unexpected deduplication on results -
i have active record query select objects based on join of table , clause. result might include same object several times , desired behaviour.
for example query, 3 results of 2 rows identical.
i want eager load association. if use includes
, query still produces 3 rows, generated query suboptimal:
puts l.count # 3 l = l.includes(:name) puts l.count #3 puts l.to_a.count #3
by forcing use of eager_load
, generated query optimized, somehow lose duplicate row:
puts l.count # 3 l = l.eager_load(:name) puts l.count # 2 puts l.to_a.count #2
the strange thing is, if manually execute generated query, 3 rows. means active record performs deduplication. why happen , there way work around issue?
something noticed during experiments optimal query (and might related) l.count
, l.to_a.count
not produce same result:
puts l.count # 3 l = l.joins(:name).includes(:name) puts l.count # 3 puts l.to_a.count # 2
Comments
Post a Comment