Skip to content
This repository has been archived by the owner on Sep 27, 2021. It is now read-only.

Paginate doesn't work with groupBy same as in Laravel #388

Open
ndragun92 opened this issue Aug 31, 2018 · 0 comments
Open

Paginate doesn't work with groupBy same as in Laravel #388

ndragun92 opened this issue Aug 31, 2018 · 0 comments
Assignees

Comments

@ndragun92
Copy link

Paginate doesn't work with groupBy same as in Laravel (Total Records)

Message from Laravel

"Currently, pagination operations that use a groupBy statement cannot be executed efficiently by Laravel. If you need to use a groupBy with a paginated result set, it is recommended that you query the database and create a paginator manually."

Example

 query = await CvLookup
        .query()
        .select('id', 'company_id')
        .sum('number as total')
        .where('day', '>=', moment(allParams.from_date).format('YYYY-MM-DD'))
        .where('day', '<=', moment(allParams.to_date).format('YYYY-MM-DD'))
        .groupBy('company_id')
        .paginate(allParams.page, allParams.limit)

Result

 {
            "total": 1,
            "perPage": 2,
            "page": 1,
            "lastPage": 1,
            "data": [
                {
                    "id": 1,
                    "company_id": 5,
                    "total": "20"
                },
                {
                    "id": 2,
                    "company_id": 5,
                    "total": "100"
                }
            ]
        }
@thetutlage thetutlage self-assigned this Sep 1, 2018
@thetutlage thetutlage transferred this issue from adonisjs/lucid Nov 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants