feathersjs / feathers

The API and real-time application framework
https://feathersjs.com
MIT License
15.07k stars 752 forks source link

page parameter "total" is not the actual number of items in the database when using composite primary key #2869

Closed Leo843 closed 2 years ago

Leo843 commented 2 years ago

Description

When a GET request is made to the REST API, parameter "total" in the response is not the actual number of items in the database table.

This behavior occurs when a service uses Sequelize with PostgreSQL and the model is defined with a composite primary key (more than one primary key).

Steps to reproduce

I made a repo to reproduce the issue. Clone the repository and run docker compose run test-runner.

Expected behavior

Parameter "total" must always be the actual number of items in the table, even when the model uses a composite primary key.

daffl commented 2 years ago

This is likely a duplicate of https://github.com/feathersjs-ecosystem/feathers-sequelize/issues/343

Leo843 commented 2 years ago

Just stumbled on this. Waiting for a fix, but until then try adding this to your Sequelize model (syntax as of Sequelize v4):

hooks: {
  beforeCount(options) {
    options.distinct = false;
  },
},

Originally posted by @1valdis in https://github.com/feathersjs-ecosystem/feathers-sequelize/issues/343#issuecomment-874798529

Doing this, fixed the issue for me.