-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Closed
Labels
type: bugDEPRECATED: replace with the "bug" issue typeDEPRECATED: replace with the "bug" issue type
Description
What are you doing?
When using a model with mapped fields eg:
const Foo = sequelize.define('Foo', {
fooId: {
field: 'foo_id', // mapped
type: DataTypes.INTEGER,
autoIncrement: true,
primaryKey: true,
},
statusId: {
field: 'status_id', // mapped
type: DataTypes.INTEGER,
autoIncrement: true,
primaryKey: true,
}
...and a scope:
Foo.addScope('defaultScope', {
where: {
statusId: { [sequelize.Op.ne]: 0 },
}
})executing find queries and count have different results:
Foo.findAll({ where: { statusId: 0 } }) // generate sql: Foo.statusId = 0
Foo.count({ where: { statusId: 0 } }) // generate sql: Foo.statusId != 0Looking into the code look like that injecting the scope after calling Utils.mapOptionFieldNames(options, this) twice, before injecting the scope causes the issue.
Dialect: any
Sequelize version: 4.38.0
Tested with latest release: yes
Note : Your issue may be ignored OR closed by maintainers if it's not tested against latest version OR does not follow issue template.
Metadata
Metadata
Assignees
Labels
type: bugDEPRECATED: replace with the "bug" issue typeDEPRECATED: replace with the "bug" issue type