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_id
s with their corresponding values being the count of Rating
s for this drill_id
. See AR::Calculations#count for details.
You want to know how many drill_id
s there are between all your Rating
s instead? Choose one:
Fix the query
Rating.select('DISTINCT drill_id').count
Count the keys
Rating.paginate(page: 1, group: 'drill_id').keys.count
精彩评论