Skip to content

Commit

Permalink
Fix MSSQL returning values for bulkUpdate
Browse files Browse the repository at this point in the history
- bulkUpdate will now return the updates if options.returning is true.
- updateQuery removed duplicate setting check
- Fix documentation for model.update
  • Loading branch information
ShaharHD committed Jun 23, 2020
1 parent 7fba668 commit 2ce6722
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/dialects/abstract/query-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ class QueryGenerator {

suffix += selectFromTmp;
}
} else if (this._dialect.supports.returnValues && options.returning) {
} else if (options.returning) {
// ensure that the return output is properly mapped to model fields.
options.mapToModel = true;
suffix += ' RETURNING *';
Expand Down
5 changes: 4 additions & 1 deletion lib/dialects/mssql/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,10 @@ class Query extends AbstractQuery {
return data[0];
}
if (this.isBulkUpdateQuery()) {
return data.length;
if (this.options.returning)
return this.handleSelectQuery(data);
else
return data.length;
}
if (this.isBulkDeleteQuery()) {
return data[0] && data[0].AFFECTEDROWS;
Expand Down
2 changes: 1 addition & 1 deletion types/lib/model.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
* 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,
Expand Down

0 comments on commit 2ce6722

Please sign in to comment.