开发者

Count and association eager loading

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜