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

Commit 1a16b915 by roikoren755 Committed by GitHub

fix(utils): clone attributes before mutating them (#13226)

1 parent 39299a63
...@@ -186,6 +186,7 @@ exports.mapOptionFieldNames = mapOptionFieldNames; ...@@ -186,6 +186,7 @@ exports.mapOptionFieldNames = mapOptionFieldNames;
function mapWhereFieldNames(attributes, Model) { function mapWhereFieldNames(attributes, Model) {
if (attributes) { if (attributes) {
attributes = cloneDeep(attributes);
getComplexKeys(attributes).forEach(attribute => { getComplexKeys(attributes).forEach(attribute => {
const rawAttribute = Model.rawAttributes[attribute]; const rawAttribute = Model.rawAttributes[attribute];
......
...@@ -19,6 +19,7 @@ describe(Support.getTestDialectTeaser('associations'), () => { ...@@ -19,6 +19,7 @@ describe(Support.getTestDialectTeaser('associations'), () => {
commentable: Sequelize.STRING, commentable: Sequelize.STRING,
commentable_id: Sequelize.INTEGER, commentable_id: Sequelize.INTEGER,
isMain: { isMain: {
field: 'is_main',
type: Sequelize.BOOLEAN, type: Sequelize.BOOLEAN,
defaultValue: false defaultValue: false
} }
...@@ -298,6 +299,11 @@ describe(Support.getTestDialectTeaser('associations'), () => { ...@@ -298,6 +299,11 @@ describe(Support.getTestDialectTeaser('associations'), () => {
expect(comment.type).to.match(/blue|green/); expect(comment.type).to.match(/blue|green/);
} }
}); });
it('should not mutate scope when running SELECT query (#12868)', async function() {
await this.sequelize.sync({ force: true });
await this.Post.findOne({ where: {}, include: [{ association: this.Post.associations.mainComment, attributes: ['id'], required: true, where: {} }] });
expect(this.Post.associations.mainComment.scope.isMain).to.equal(true);
});
}); });
if (Support.getTestDialect() !== 'sqlite') { if (Support.getTestDialect() !== 'sqlite') {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!