Skip to content

ActiveRecord sum is broken on pages greater than 1 #550

Description

@donkey-hotei

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 ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions