与组选项一起使用时,will_paginate 无法获得正确的页数

发布于 2024-12-23 11:19:30 字数 876 浏览 0 评论 0原文

我仍然停留在 Rails 2.3.8 应用程序上。最近我安装了“will_paginate”gem,让我的页面生成变得更轻松。大多数时候它工作得很好,但是当我设置 :group 选项时,页数计算错误。

示例:

@items = Item.find(:all, :select => 'items.*, count(accounts_items.id) as users_count',:joins => 'join accounts_items on accounts.id = accounts_items.item_id', :group => 'items.id').paginate :page=>params[:page],:per_page=>12

当我检查从日志执行的查询时,它们看起来像这样:

SELECT items.*, count(accounts_items.id) as users_count FROM items join statements_items on items.id = account_items.item_id GROUP BY space.id ORDER BY users_count DESC LIMIT 0, 12

SELECT count(*) AS count_all FROM items joinaccounts_items on item.id = account_spaces.space_id

第一个查询工作完美,并为我提供了每件物品所需的所有信息,而第二个查询并不是计算物品数量的正确查询。

有办法解决这个问题吗?如果是的话怎么办?

多谢

I am still stuck at a Rails 2.3.8 application. Recently I installed 'will_paginate' gem to make my life a bit easier with generating pages. It works really well most of the times, but when I set the :group option the number of pages is wrongly calculated.

example:

@items = Item.find(:all, :select => 'items.*, count(accounts_items.id) as users_count',:joins => 'join accounts_items on accounts.id = accounts_items.item_id', :group => 'items.id').paginate :page=>params[:page],:per_page=>12

When I checked the queries performed from the logs they looked like this:

SELECT items.*, count(accounts_items.id) as users_count FROM items join accounts_items on items.id = accounts_items.item_id GROUP BY spaces.id ORDER BY users_count DESC LIMIT 0, 12

SELECT count(*) AS count_all FROM items join accounts_items on item.id = accounts_spaces.space_id

The first query works perfectly and gets me all the information needed for each item, while the second one is just not the right query to count my items.

Is there a way to fix this? If yes how?

Thanks a lot

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文