Skip to content

Commit

Permalink
fix(mssql): omit empty pk values for upsert
Browse files Browse the repository at this point in the history
  • Loading branch information
sushantdhiman committed May 24, 2020
1 parent 9d8a7d3 commit 0c10665
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/dialects/mssql/query-interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ class MSSqlQueryInterface extends QueryInterface {
wheres.push(where);
}

const primaryKeys = Object.values(model.primaryKeys).map(item => item.field);

for (const primaryKeyField of primaryKeys) {
if (primaryKeyField in insertValues && insertValues[primaryKeyField] === null) {
delete insertValues[primaryKeyField];
}
if (primaryKeyField in updateValues && updateValues[primaryKeyField] === null) {
delete updateValues[primaryKeyField];
}
}

// Lets combine unique keys and indexes into one
let indexes = Object.values(model.uniqueKeys).map(item => item.fields);
indexes = indexes.concat(Object.values(model._indexes).filter(item => item.unique).map(item => item.fields));
Expand Down

0 comments on commit 0c10665

Please sign in to comment.