Pagination plugin ignores transactions#1625
Conversation
This fixes bookshelf#1623 by passing the options used (including the current transaction, if any) to both the pager and the counter methods.
Passing only the `transacting` property means that `withRelated`, `required`, and other options will only apply to the pager fetch.
src/plugins/pagination.js
Outdated
| qb.countDistinct.apply(qb, [`${tableName}.${idAttribute}`]); | ||
|
|
||
| }).fetchAll().then(result => { | ||
| }).fetchAll({transacting}).then(result => { |
There was a problem hiding this comment.
would it make more sense to pass in fetchOptions directly here?
I'm using the bookshelf-paranoia plugin and it passes in withDeleted option, which pulls in records if they're softdeleted or not. Since it doesn't get passed to the pagination plugin, it only counts rows that are not soft deleted.
There was a problem hiding this comment.
I think passing all options might be a problem, as this includes passing things like require. I'd argue that the require must apply to the fetchAll of the rows you want, not the count. I don't know if this matters in practice, or why the count is using a fetchAll rather than a fetch anyway. It would also be passing withRelated, which will fail in the worst case or be wasteful in the best case. Maybe just blacklisting some options to exclude could work, though it presents some forward compatibility issues.
|
Any plans to merge this? |
|
@mrhwick might have a different opinion, but I think this PR needs to have at least one test added for this before it's merged. |
|
A regression test would be useful. I'll take a look at #1623 and see if I can derive a reproduction case from there to write a regression test for this change. |
|
@jordansexton Can you add tests to verify the correct behavior of this bug fix? |
ricardograca
left a comment
There was a problem hiding this comment.
Looks good and fixes two issues at once. I'll add a test for these changes after this is merged.
Pagination plugin ignores transactions
Introduction
This fixes #1623 and fixes #1645 by passing the the current transaction (if any) to both the pager and the counter methods. This fix may conflict with changes made in #1561 (superseding #1272 and #1261). Perhaps @vellotis wants to weigh in?