Kaltsoon / sequelize-cursor-pagination

➡️ Cursor-based pagination queries for Sequelize models
87 stars 27 forks source link

Pass queryArgs to count queries #39

Closed Iamhere closed 3 years ago

Iamhere commented 3 years ago

Fix wrong total count when inner join is used. For example:

Test.paginate({ 
limit: 2, 
include: [{
                    model: SomeModel,
                    required: true
                }],
 })
korifey91 commented 3 years ago

Good catch @Iamhere !

I was needed to implement my own paginate method in my project based on this package in order to make it works correctly.

But one more thing is required since Model.count counts associated raws if include presents.

const [instances, { length: totalCount }, { length: cursorCount }] =
      await Promise.all([
        Model.findAll(paginationQueryOptions),
        Model.findAll(totalCountQueryOptions),
        Model.findAll(cursorCountQueryOptions),
      ]);
Kaltsoon commented 3 years ago

Good catch!