bal*_*and 5 activerecord ruby-on-rails ruby-on-rails-3 kaminari
我正在使用Kaminari对查询中的一些结果进行分页,其中我正在选择不同的记录.请考虑以下控制器代码:
@things = Thing.joins... # create a complex query that produces duplicate results
# I want to select distinct results: this produces the correct results
@things = @things.select("DISTINCT things.*")
# when Kaminari calls count, it will run "SELECT COUNT(*)", instead of
# "SELECT COUNT(DISTINCT things.*)" we will get the wrong count and extra pages
@things = @things.page(params[:page]).per(10)
Run Code Online (Sandbox Code Playgroud)
我能想到的最好的解决方案是传递:distinct => true
给count
像Kaminari的开发人员拒绝的拉动请求.这个SO问题讨论了潜在的问题.这行代码是违规的调用count
.
是否有任何变通方法可以为Kaminari提供正确的计数,而不需要修补Kaminari?谢谢.
更新: