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

Commit e36212c8 by Shahar Hadas Committed by GitHub

fix(mssql): returning data for bulkUpdate (#12413)

1 parent 77b5fe6f
......@@ -197,6 +197,10 @@ class Query extends AbstractQuery {
return data[0];
}
if (this.isBulkUpdateQuery()) {
if (this.options.returning) {
return this.handleSelectQuery(data);
}
return rowCount;
}
if (this.isBulkDeleteQuery()) {
......
......@@ -134,6 +134,25 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
}
if (_.get(current.dialect.supports, 'returnValues.output')) {
it('should output the updated record', async function() {
const account = await this.Account.create({ ownerId: 2 });
const [, accounts] = await this.Account.update({ name: 'FooBar' }, {
where: {
id: account.get('id')
},
returning: true
});
const firstAcc = accounts[0];
expect(firstAcc.name).to.be.equal('FooBar');
await firstAcc.reload();
expect(firstAcc.ownerId, 'Reloaded as output update only return primary key and changed fields').to.be.equal(2);
});
}
if (current.dialect.supports['LIMIT ON UPDATE']) {
it('should only update one row', async function() {
await this.Account.create({
......
......@@ -2010,7 +2010,7 @@ export abstract class Model<T = any, T2 = any> extends Hooks {
/**
* Update multiple instances that match the where options. The promise returns an array with one or two
* elements. The first element is always the number of affected rows, while the second element is the actual
* affected rows (only supported in postgres with `options.returning` true.)
* affected rows (only supported in postgres and mssql with `options.returning` true.)
*/
public static update<M extends Model>(
this: { new(): M } & typeof Model,
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!