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

Commit 5d0d6a44 by Dario Committed by Sushant

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

1 parent 5ddb26f4
......@@ -1999,8 +1999,6 @@ class Model {
col = this.name + '.' + (options.col || this.primaryKeyField);
}
Utils.mapOptionFieldNames(options, this);
options.plain = !options.group;
options.dataType = new DataTypes.INTEGER();
options.includeIgnoreAttributes = false;
......
......@@ -17,6 +17,10 @@ describe(Support.getTestDialectTeaser('Model'), () => {
this.ScopeMe = this.sequelize.define('ScopeMe', {
username: Sequelize.STRING,
email: Sequelize.STRING,
aliasValue: {
field: 'alias_value',
type: Sequelize.INTEGER
},
access_level: Sequelize.INTEGER,
other_value: Sequelize.INTEGER
}, {
......@@ -66,7 +70,12 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}
}]
};
}
},
withAliasedField: {
where: {
aliasValue: { [Sequelize.Op.ne]: 1 }
}
},
}
});
this.Child.belongsTo(this.ScopeMe);
......@@ -74,10 +83,10 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return this.sequelize.sync({force: true}).then(() => {
const records = [
{username: 'tony', email: 'tony@sequelizejs.com', access_level: 3, other_value: 7},
{username: 'tobi', email: 'tobi@fakeemail.com', access_level: 10, other_value: 11},
{username: 'dan', email: 'dan@sequelizejs.com', access_level: 5, other_value: 10},
{username: 'fred', email: 'fred@foobar.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, aliasValue: 5 },
{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, aliasValue: 10 }
];
return this.ScopeMe.bulkCreate(records);
}).then(() => {
......@@ -114,6 +123,10 @@ describe(Support.getTestDialectTeaser('Model'), () => {
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() {
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!