Skip to content

Commit

Permalink
Add support for custom column mapping in primary key column
Browse files Browse the repository at this point in the history
Add support for idInjection

Closes loopbackio#1
  • Loading branch information
idoshamun committed Mar 1, 2015
1 parent 6f60417 commit 87543e7
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions lib/mssql.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,11 +392,13 @@ MsSQL.prototype.buildInsert = function (model, data) {
var params = [];
var props = this._models[model].properties;
var modelPKID = this.idName(model);
//remove the pkid column if it's in the data, since we're going to insert a
// new record, not update an existing one.
delete data[modelPKID];
//delete the hardcoded id property that jugglindb automatically creates
delete data.id;
if (props[modelPKID].idInjection !== false) {
//remove the pkid column if it's in the data, since we're going to insert a
// new record, not update an existing one.
delete data[modelPKID];
//delete the hardcoded id property that jugglindb automatically creates
delete data.id;
}
Object.keys(data).forEach(function (key) {
if (props[key]) {
insertIntoFields.push(self.columnEscaped(model, key));
Expand Down Expand Up @@ -1167,8 +1169,14 @@ MsSQL.prototype.propertiesSQL = function(model) {
if (prop === modelPKID) {
var idProp = objModel.properties[modelPKID];
if (idProp.type === Number) {
sql.push(self.columnEscaped(model, modelPKID) +
" [int] IDENTITY(1,1) NOT NULL");
if(idProp.generated !== false) {
sql.push(self.columnEscaped(model, modelPKID) +
" " + self.columnDataType(model, modelPKID) + " IDENTITY(1,1) NOT NULL");
}
else {
sql.push(self.columnEscaped(model, modelPKID) +
" " + self.columnDataType(model, modelPKID) + " NOT NULL");
}
continue;
} else if (idProp.type === String) {
if(idProp.generated) {
Expand Down

0 comments on commit 87543e7

Please sign in to comment.