Will_paginate 给出“不寻常的”;使用 group 子句时的计数结果
使用 Rails3 和 will_paginate 3.0.2 并看到一个不寻常的问题:
Rating.paginate(:page => 1).count
=> 3
但是如果我添加组子句:
Rating.paginate(:page => 1, :group => "drill_id").count
=> {3=>2, 4=>1}
我找到的最接近的 Google 结果是: https://github.com/mislav/will_paginate/issues/167
但这似乎并不是完全相同的问题。有什么想法吗?
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 be the exact same issue.Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将从
#count
获得分组结果。它基本上是每个drill_id
的Rating
计数。结果哈希的键是drill_id
,其对应的值是该drill_id
的Rating
计数。有关详细信息,请参阅 AR::Calculations#count。您想知道您的所有
Rating
之间有多少个drill_id
吗?选择一项:修复查询
Rating.select('DISTINCTrill_id').count
对键进行计数
Rating.paginate(页:1,组:'drill_id').keys.count
You are getting a grouped result from
#count
. It's basically a count ofRating
perdrill_id
. The keys of the result hash aredrill_id
s with their corresponding values being the count ofRating
s for thisdrill_id
. See AR::Calculations#count for details.You want to know how many
drill_id
s there are between all yourRating
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