Skip to content

broken fix: count just the right number of row #304 #321

@artur-krueger

Description

@artur-krueger

This line leads to a broken behavior.
https://github.com/moleculerjs/moleculer-db/pull/304/files#diff-35fc753ffb17451ff92b1bad2bff715aaa5ff65f4e08b7cce5290fe4e5003d4aR305

If includes are defined in the model, then this behavior is done automatically correctly by sequelize itself.

This is the relevant code from sequelize model.js, and you can see it's doing the settimg already automatically:

  static async count(options) {
    ...
    if (options.include) {
      col = `${this.name}.${options.col || this.primaryKeyField}`;
    }
    ...

By setting the col field in the options to 'tablename.primaryColumn', the resulting col will be composed to by sequelize to "tablename.tablename.primaryColumn" and later converted to 'tablename->tablename.primaryColumn'. The result is a broken sql query.

The right behavior is to set just the column name:

const strictCountRule = { distinct: true, col: `${this.model.primaryKeyAttribute}` };

or even better to skip this at all and let sequelize do it right.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions