Will_paginate 给出“不寻常的”;使用 group 子句时的计数结果

发布于 2024-12-08 02:32:27 字数 503 浏览 0 评论 0原文

使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

土豪 2024-12-15 02:32:27

您将从 #count 获得分组结果。它基本上是每个 drill_idRating 计数。结果哈希的键是 drill_id,其对应的值是该 drill_idRating 计数。有关详细信息,请参阅 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 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').count

  • Count the keys

    Rating.paginate(page: 1, group: 'drill_id').keys.count

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文