-
-
Notifications
You must be signed in to change notification settings - Fork 93
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
Pagination plugin returns incorect number of pages #366
Comments
@flash-gordon it calls |
@solnic 🤦♂ ok |
@flash-gordon oh wow that is puzzling |
Got it, rom-sql/lib/rom/sql/plugin/pagination.rb Lines 115 to 121 in bde6843
It happens because pager is eagerly evaluated and passed around with options when you chain relation calls. It means it always sticks to the default dataset. This is 💯 a bug, we should use memoization instead
|
So, I just was bitten by this. And I discovered a funny thing, maybe it'd help someone: relation.where { ... }.per_page(per_page).page(page) # this works correctly
relation.per_page(per_page).page(page).where { ... } # this does not Anyway, I thought I could try to fix it and make a PR, but it seems that tests are currently not passing on |
@katafrakt please target release-3.5 branch and then I could cherry-pick your fix into master |
Describe the bug
If you paginate over a filtered relation (say,
users.active
) thenrel.total
will return incorrect results since it callsdataset.unfiltered
which discard all the filtering.To Reproduce
user.active.pager.total
returns the total number of usersExpected behavior
user.active.pager.total
returns the number of active usersYour environment
The text was updated successfully, but these errors were encountered: