sequelize-paginate icon indicating copy to clipboard operation
sequelize-paginate copied to clipboard

Count includes records regardless of include

Open dsmackie opened this issue 5 years ago • 4 comments

When a query has an include with a where condition, the result set matches the query but the total record count includes all available records.

let articles = Articles.paginate({
  where: {
    active: true
  },
  include: {
    model: Organisations,
    where: {
      id: 1
    }
  }
});

The above will return the correct records, but count ignores the include where criteria and returns the count of all records.

Line https://github.com/eclass/sequelize-paginate/blob/master/src/index.js#L50 appears to be responsible.

dsmackie avatar Apr 07 '19 00:04 dsmackie

@lgaticaq

u just have to remove include form array in this code snippet:

`

   if (!['order', 'attributes', 'include'].includes(key)) {
      // eslint-disable-next-line security/detect-object-injection
      acc[key] = options[key]
    }
    return acc
  }, {})`

Amgad-Atef-Mohamed avatar Apr 30 '19 11:04 Amgad-Atef-Mohamed

@Amgad-Atef-Mohamed Can you send a pull request??

gabrieldissotti avatar Jul 31 '19 17:07 gabrieldissotti

@gabrieldissotti I see u don't need this package anymore,

sequelize package already has pagination built-in: https://sequelize.org/master/class/lib/model.js~Model.html#static-method-findAndCountAll

Amgad-Atef-Mohamed avatar Jul 31 '19 18:07 Amgad-Atef-Mohamed

@Amgad-Atef-Mohamed Thanks!!

gabrieldissotti avatar Jul 31 '19 18:07 gabrieldissotti