-
-
Notifications
You must be signed in to change notification settings - Fork 199
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
paginate does not work when called on a stored query object #1087
Comments
Can you please share how do you verify the behavior of pagination working and not working? Maybe share the complete example and the result you get + expected output. |
OR
result =
I expect to receive the structure of a page (meta and data) and also receive the number of rows I request from the page.
@thetutlage Thanks for the quick response! |
In the first example, it does not work because the paginate method executes the query and not mutates the query builder. Make sure to always call the public async index({ request }: HttpContext) {
const query = Post.query().select(...this.selectFields)
const qs = request.qs()
// pagination logic
const page = qs.page || 1
const limit = qs.perPage || 5
- query.paginate(page, limit)
// sort logic
if (qs.sortBy) {
query.orderBy(qs.sortBy, qs.sortDesc ? 'desc' : 'asc')
}
- return query
+ return query.paginate(page, limit)
} |
Package version
21.5.1
Describe the bug
Description
There seems to be an issue with the paginate method when attempting to use it on a query stored in a variable.
Steps to Reproduce
Post.query()
:In contrast, calling paginate directly in the query chain works fine:
Expected Behavior
The paginate method should work even when called on a stored query object, like this:
Actual Behavior
The paginate method only works when called directly in the query chain. When called on a stored query object, it fails to execute as expected.
Possible Root Cause
The issue might be related to how Lucid handles the query state internally. Storing the query in a variable might lose certain required configurations or bindings needed by paginate.
Environment Details
AdonisJS Version: v6
Lucid ORM Version: 21.5.1
Node.js Version: v20.15.0
Operating System: Ubuntu 24.04
package manager: pnpm
Reproduction repo
No response
The text was updated successfully, but these errors were encountered: