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?
精彩评论