Skip to content
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

ActiveRecord sum is broken on pages greater than 1 #550

Open
donkey-hotei opened this issue Aug 2, 2017 · 0 comments
Open

ActiveRecord sum is broken on pages greater than 1 #550

donkey-hotei opened this issue Aug 2, 2017 · 0 comments

Comments

@donkey-hotei
Copy link

donkey-hotei commented Aug 2, 2017

Hello, perhaps this is application specific but it seems as though summing on pages greater than one sums the records incorrectly. Although resolving the query to an array with map and then calling sum over the elements sums correctly.

[1] pry(main)> Trip.paginate(page: 2).sum('distance')
   (2.5ms)  SELECT  SUM("trips"."distance") FROM "trips" LIMIT $1 OFFSET $2  [["LIMIT", 30], ["OFFSET", 30]]
=> 0.0
[2] pry(main)> Trip.paginate(page: 1).sum('distance')
   (0.6ms)  SELECT  SUM("trips"."distance") FROM "trips" LIMIT $1 OFFSET $2  [["LIMIT", 30], ["OFFSET", 0]]
=> 10542.792252

Is this a bug in will_paginate ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant