与组选项一起使用时,will_paginate 无法获得正确的页数
我仍然停留在 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, 12SELECT 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, 12SELECT 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论