Skip to content

Commit

Permalink
fix: count just the right number of row
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Ferrero committed Jan 10, 2022
1 parent 922c982 commit cc9cc07
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/moleculer-db-adapter-sequelize/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,10 @@ class SequelizeDbAdapter {
* @returns {Promise}
*/
createCursor(params, isCounting) {
const strictCountRule = { distinct: true, col: `${this.model.tableName}.${this.model.primaryKeyAttribute}` };
if (!params) {
if (isCounting)
return this.model.count();
return this.model.count(strictCountRule);

return this.model.findAll();
}
Expand Down Expand Up @@ -356,7 +357,7 @@ class SequelizeDbAdapter {
q.limit = params.limit;

if (isCounting)
return this.model.count(q);
return this.model.count(_.merge(q, strictCountRule));

return this.model.findAll(q);
}
Expand Down

0 comments on commit cc9cc07

Please sign in to comment.