fix(utils): clone attributes before mutating them (#13226) · sequelize/sequelize@1a16b91

File tree

2 files changed

lines changed

  • test/integration/associations

2 files changed

lines changed

Original file line numberDiff line numberDiff line change

@@ -186,6 +186,7 @@ exports.mapOptionFieldNames = mapOptionFieldNames;

186186
187187

function mapWhereFieldNames(attributes, Model) {

188188

if (attributes) {

189+

attributes = cloneDeep(attributes);

189190

getComplexKeys(attributes).forEach(attribute => {

190191

const rawAttribute = Model.rawAttributes[attribute];

191192
Original file line numberDiff line numberDiff line change

@@ -19,6 +19,7 @@ describe(Support.getTestDialectTeaser('associations'), () => {

1919

commentable: Sequelize.STRING,

2020

commentable_id: Sequelize.INTEGER,

2121

isMain: {

22+

field: 'is_main',

2223

type: Sequelize.BOOLEAN,

2324

defaultValue: false

2425

}

@@ -298,6 +299,11 @@ describe(Support.getTestDialectTeaser('associations'), () => {

298299

expect(comment.type).to.match(/blue|green/);

299300

}

300301

});

302+

it('should not mutate scope when running SELECT query (#12868)', async function() {

303+

await this.sequelize.sync({ force: true });

304+

await this.Post.findOne({ where: {}, include: [{ association: this.Post.associations.mainComment, attributes: ['id'], required: true, where: {} }] });

305+

expect(this.Post.associations.mainComment.scope.isMain).to.equal(true);

306+

});

301307

});

302308
303309

if (Support.getTestDialect() !== 'sqlite') {