不要怂,就是干,撸起袖子干!

Commit e3bba447 by Dario Committed by Sushant

fix(count): duplicate mapping of fields break scopes (#9821)

1 parent 2c3a6e71
...@@ -1850,8 +1850,6 @@ class Model { ...@@ -1850,8 +1850,6 @@ class Model {
col = this.name + '.' + (options.col || this.primaryKeyField); col = this.name + '.' + (options.col || this.primaryKeyField);
} }
Utils.mapOptionFieldNames(options, this);
options.plain = !options.group; options.plain = !options.group;
options.dataType = new DataTypes.INTEGER(); options.dataType = new DataTypes.INTEGER();
options.includeIgnoreAttributes = false; options.includeIgnoreAttributes = false;
......
...@@ -16,6 +16,10 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -16,6 +16,10 @@ describe(Support.getTestDialectTeaser('Model'), () => {
this.ScopeMe = this.sequelize.define('ScopeMe', { this.ScopeMe = this.sequelize.define('ScopeMe', {
username: Sequelize.STRING, username: Sequelize.STRING,
email: Sequelize.STRING, email: Sequelize.STRING,
aliasValue: {
field: 'alias_value',
type: Sequelize.INTEGER
},
access_level: Sequelize.INTEGER, access_level: Sequelize.INTEGER,
other_value: Sequelize.INTEGER other_value: Sequelize.INTEGER
}, { }, {
...@@ -65,7 +69,12 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -65,7 +69,12 @@ describe(Support.getTestDialectTeaser('Model'), () => {
} }
}] }]
}; };
},
withAliasedField: {
where: {
aliasValue: { [Sequelize.Op.ne]: 1 }
} }
},
} }
}); });
this.Child.belongsTo(this.ScopeMe); this.Child.belongsTo(this.ScopeMe);
...@@ -73,10 +82,10 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -73,10 +82,10 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.sequelize.sync({force: true}).then(() => { return this.sequelize.sync({force: true}).then(() => {
const records = [ const records = [
{username: 'tony', email: 'tony@sequelizejs.com', access_level: 3, other_value: 7}, {username: 'tony', email: 'tony@sequelizejs.com', access_level: 3, other_value: 7, aliasValue: 12 },
{username: 'tobi', email: 'tobi@fakeemail.com', access_level: 10, other_value: 11}, {username: 'tobi', email: 'tobi@fakeemail.com', access_level: 10, other_value: 11, aliasValue: 5 },
{username: 'dan', email: 'dan@sequelizejs.com', access_level: 5, other_value: 10}, {username: 'dan', email: 'dan@sequelizejs.com', access_level: 5, other_value: 10, aliasValue: 1 },
{username: 'fred', email: 'fred@foobar.com', access_level: 3, other_value: 7} {username: 'fred', email: 'fred@foobar.com', access_level: 3, other_value: 7, aliasValue: 10 }
]; ];
return this.ScopeMe.bulkCreate(records); return this.ScopeMe.bulkCreate(records);
}).then(() => { }).then(() => {
...@@ -113,6 +122,10 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -113,6 +122,10 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return expect(this.ScopeMe.scope('lowAccess').count({ where: { username: 'dan'}})).to.eventually.equal(1); return expect(this.ScopeMe.scope('lowAccess').count({ where: { username: 'dan'}})).to.eventually.equal(1);
}); });
it('should be able to merge scopes with where on aliased fields', function() {
return expect(this.ScopeMe.scope('withAliasedField').count({ where: { aliasValue: 5 } })).to.eventually.equal(1);
});
it('should ignore the order option if it is found within the scope', function() { it('should ignore the order option if it is found within the scope', function() {
return expect(this.ScopeMe.scope('withOrder').count()).to.eventually.equal(4); return expect(this.ScopeMe.scope('withOrder').count()).to.eventually.equal(4);
}); });
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!