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

Commit ff93d7c4 by javiertury Committed by Sushant

fix(search_path): disable bindParam in updateQuery (#11236)

1 parent 47489ab1
......@@ -338,13 +338,19 @@ class QueryGenerator {
const values = [];
const bind = [];
const bindParam = options.bindParam === undefined ? this.bindParam(bind) : options.bindParam;
const modelAttributeMap = {};
let outputFragment ='';
let tmpTable = ''; // tmpTable declaration for trigger
let selectFromTmp = ''; // Select statement for trigger
let suffix = '';
if (_.get(this, ['sequelize', 'options', 'dialectOptions', 'prependSearchPath']) || options.searchPath) {
// Not currently supported with search path (requires output of multiple queries)
options.bindParam = false;
}
const bindParam = options.bindParam === undefined ? this.bindParam(bind) : options.bindParam;
if (this._dialect.supports['LIMIT ON UPDATE'] && options.limit) {
if (this.dialect !== 'mssql') {
suffix = ` LIMIT ${this.escape(options.limit)} `;
......
......@@ -467,6 +467,40 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
});
});
describe('Edit data via instance.update, retrieve updated instance via model.findAll', () => {
it('should be able to update data via instance update in both schemas, and retrieve it via findAll with where', function() {
const Restaurant = this.Restaurant;
return Promise.all([
Restaurant.create({ foo: 'one', bar: '1' }, { searchPath: SEARCH_PATH_ONE })
.then(rnt => rnt.update({ bar: 'x.1' }, { searchPath: SEARCH_PATH_ONE })),
Restaurant.create({ foo: 'one', bar: '2' }, { searchPath: SEARCH_PATH_ONE })
.then(rnt => rnt.update({ bar: 'x.2' }, { searchPath: SEARCH_PATH_ONE })),
Restaurant.create({ foo: 'two', bar: '1' }, { searchPath: SEARCH_PATH_TWO })
.then(rnt => rnt.update({ bar: 'x.1' }, { searchPath: SEARCH_PATH_TWO })),
Restaurant.create({ foo: 'two', bar: '2' }, { searchPath: SEARCH_PATH_TWO })
.then(rnt => rnt.update({ bar: 'x.2' }, { searchPath: SEARCH_PATH_TWO }))
]).then(() => Promise.all([
Restaurant.findAll({
where: { bar: 'x.1' },
searchPath: SEARCH_PATH_ONE
}).then(restaurantsOne => {
expect(restaurantsOne.length).to.equal(1);
expect(restaurantsOne[0].foo).to.equal('one');
expect(restaurantsOne[0].bar).to.equal('x.1');
}),
Restaurant.findAll({
where: { bar: 'x.2' },
searchPath: SEARCH_PATH_TWO
}).then(restaurantsTwo => {
expect(restaurantsTwo.length).to.equal(1);
expect(restaurantsTwo[0].foo).to.equal('two');
expect(restaurantsTwo[0].bar).to.equal('x.2');
})
]));
});
});
});
}
});
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!