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

Commit ad1c1537 by Shahar Hadas Committed by GitHub

fix(mssql): bulkUpdate returning values (#12410)

1 parent 26fcbce2
...@@ -210,7 +210,11 @@ class Query extends AbstractQuery { ...@@ -210,7 +210,11 @@ class Query extends AbstractQuery {
return data[0]; return data[0];
} }
if (this.isBulkUpdateQuery()) { if (this.isBulkUpdateQuery()) {
return data.length; if (this.options.returning) {
return this.handleSelectQuery(data);
}
return rowCount;
} }
if (this.isBulkDeleteQuery()) { if (this.isBulkDeleteQuery()) {
return data[0] && data[0].AFFECTEDROWS; return data[0] && data[0].AFFECTEDROWS;
......
...@@ -139,6 +139,25 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -139,6 +139,25 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}); });
} }
if (_.get(current.dialect.supports, 'returnValues.output')) {
it('should output the updated record', function() {
return this.Account.create({ ownerId: 2 }).then(account => {
return this.Account.update({ name: 'FooBar' }, {
where: {
id: account.get('id')
},
returning: true
}).then(([, accounts]) => {
const firstAcc = accounts[0];
expect(firstAcc.name).to.be.equal('FooBar');
return firstAcc.reload();
}).then(accountReloaded => {
expect(accountReloaded.ownerId, 'Reloaded as output update only return primary key and changed fields').to.be.equal(2);
});
});
});
}
if (current.dialect.supports['LIMIT ON UPDATE']) { if (current.dialect.supports['LIMIT ON UPDATE']) {
it('should only update one row', function() { it('should only update one row', function() {
return this.Account.create({ return this.Account.create({
......
...@@ -2043,7 +2043,7 @@ export abstract class Model<T = any, T2 = any> extends Hooks { ...@@ -2043,7 +2043,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 * 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 * 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>( public static update<M extends Model>(
this: { new (): M } & typeof 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!