Will_paginate gives 'unusual' result on count when using group clause
Using Rails3 and will_paginate 3.0.2 and seeing an unusual issue:
Rating.paginate(:page => 1).count
=> 3
BUT if I add the group clause:
Rating.paginate(:page => 1, :group => "drill_id").count
=> {3=>2, 4=>1}
The closest google result I found was this: https://github.com/mislav/will_paginate/issues/167
But this doesnt seem to b开发者_开发技巧e the exact same issue.Any ideas?
You are getting a grouped result from #count. It's basically a count of Rating per drill_id. The keys of the result hash are drill_ids with their corresponding values being the count of Ratings for this drill_id. See AR::Calculations#count for details.
You want to know how many drill_ids there are between all your Ratings instead? Choose one:
Fix the query
Rating.select('DISTINCT drill_id').countCount the keys
Rating.paginate(page: 1, group: 'drill_id').keys.count
加载中,请稍侯......
精彩评论