Skip to content
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

Count includes records regardless of include #50

Open
dsmackie opened this issue Apr 7, 2019 · 4 comments
Open

Count includes records regardless of include #50

dsmackie opened this issue Apr 7, 2019 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@dsmackie
Copy link
Contributor

dsmackie commented Apr 7, 2019

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.

@lgaticaq lgaticaq self-assigned this Apr 10, 2019
@lgaticaq lgaticaq added the bug Something isn't working label Apr 10, 2019
@Amgad-Atef-Mohamed
Copy link

@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
  }, {})`

@gabrieldissotti
Copy link

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

@Amgad-Atef-Mohamed
Copy link

@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

@gabrieldissotti
Copy link

@Amgad-Atef-Mohamed Thanks!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants