-
Notifications
You must be signed in to change notification settings - Fork 75
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
will_paginate breaks when tally or plusminus_tally is used #64
Comments
Hey Justin, Not sure what's going on, thumbs_up does use some complicated queries so that could very well be at fault. An easy workaround would be to paginate the objects first, then filter a plusminus_tally query based on that object array. Another suggestion would be to see what the query is without the #count method on the end... it'll give us a better idea of what's invalid about the SQL. Braden (Brady) Bouchard On Monday, 4 February, 2013 at 8:51 AM, Justin Bull wrote:
|
Hi Brady, Here is a regular query: irb(main):001:0> Violation.without_spammed.order("created_at DESC").page(1)
Violation Load (0.4ms) SELECT "violations".* FROM "violations" WHERE "violations"."spammed" = 'f' ORDER BY created_at DESC LIMIT 10 OFFSET 0
=> [A bunch of Violation objects] Here is the query with thumbs_up: irb(main):002:0> Violation.without_spammed.plusminus_tally.reorder("created_at DESC").page(1)
Violation Load (0.6ms) SELECT violations.*, SUM(CASE votes.vote WHEN 't' THEN 1 WHEN 'f' THEN -1 ELSE 0 END) AS plusminus_tally, COUNT(votes.id) AS vote_count FROM "violations" LEFT OUTER JOIN votes ON violations.id = votes.voteable_id AND votes.voteable_type = 'Violation' WHERE "violations"."spammed" = 'f' GROUP BY violations.id, violations.title, violations.description, violations.address, violations.violator_id, violations.created_at, violations.updated_at, violations.user_id, violations.slug, violations.flagged, violations.user_ip, violations.user_agent, violations.referrer, violations.spammed ORDER BY created_at DESC LIMIT 10 OFFSET 0
=> [A bunch of Violation objects] It looks like the |
Feel free to take a stab at fixing this query, I'm happy to take pull requests if we can make it work with will_paginate, but unfortunately I won't be able to work on it myself. |
It would appear that you'd require large restructuring of your db schema (using a junction table) in order to fix this issue. It appears neither of us have the time to fix this issue :) |
With will_paginate v3.0.pre2, I was also getting an exception when using it with thumbs_up: I was able to solve the issue by recreating the plusminus_tally query as a scope specific to my model.
Rather than ordering on the calculated score in the select statement aliased as Using the scope, I could paginate my blog posts based on the thumbs_up plusminus tally with: |
Thanks a ton, @whtt-eric! That solution worked for me. 👍 |
FYI, it doesn't work either with Kaminari. |
I'm seeing a similar issue. Even something simple like I'll have to try @whtt-eric's solution. If it works, we may want to factor the @bouchard are you still actively developing this gem? |
Happy to take pull requests if you want to fix it!
|
When using
tally
orplusminus_tally
is used in a ActiveRelation it breaks the will_paginatepage(params[:page])
orpaginate(:page => params[:page])
methods.I'm not sure who's at fault but I believe thumbs_up may be at fault the way the SQL is structured. If I run a regular relation asking for the count of records returned:
And if I use the
plusminus_tally
in the line:It appears to break what is expected: A result of 4. Please advise!
Environment:
Rails 3.2.11
thumbs_up 0.6.3
will_paginate 3.0.4
The text was updated successfully, but these errors were encountered: