-
Notifications
You must be signed in to change notification settings - Fork 864
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Count for grouped queries are not correct #331
Comments
Same here with the query:
Note: A temporary solution that I use, is to force |
Just curious why this has not been fixed. Is there something more complicated than what I did as a workaround in the count method (as described in my first comment). |
Using |
So, what would be a proper, more performant fix to will_paginate? |
I don’t think it is fixable – ActiveRecord will always do a “count per group” if the query contains a group statement (see rails/rails#7121 and similar issues). My workaround in a similar case recently: I did a second, manually crafted SQL query to get the correct total number of rows, then I used |
Rails 3.2.13, will_paginate 3.0.4
When I have a query that does grouping the result count coming from will_paginate is incorrect due to the way the query is built up for counts.
I'm thinking this may possibly be an AREL or ActiveRecord problem but I bring it up here because I would think that the problem would have been experienced here and I'm wondering if there are potentially any fixes or workarounds.
I found that if I replace the rel.count call in the WillPaginate::ActiveRecord::RelationMethods count method with rel.all.count I get the proper count.
Does anyone have any thoughts on this issue?
The AREL I have that duplicates this issue look something like:
records = MyModel.select('sum(something)').group[:user_id, :category_id]
The text was updated successfully, but these errors were encountered: