开发者

Count and association eager loading

开发者 https://www.devze.com 2023-03-10 00:47 出处:网络
Is there an effective way to get count of records while eager loading associations? Post.includes({:comments => :author}).count produces SELECT COUNT(DISTINCT id) ... LEFT OUTER JOIN ... which is f

Is there an effective way to get count of records while eager loading associations? Post.includes({:comments => :author}).count produces SELECT COUNT(DISTINCT id) ... LEFT OUTER JOIN ... which is far from optimal. Maybe some pagination plugin does it in a clever way?

EDT 开发者_如何学运维Kaminari gem is able to do it properly, although only for named scopes.


Have you tried count_by_sql?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号