Skip to content

Commit 148fce3

Browse files
committed
Merge pull request #15 from strongloop/feature/fix-arc-600
Map required/id properties to NOT NULL
2 parents 609e731 + 0e85f59 commit 148fce3

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

lib/mssql.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1183,10 +1183,15 @@ MsSQL.prototype.indexSettingsSQL = function (model, prop) {
11831183
return cmd;
11841184
};
11851185

1186+
function isNullable(p) {
1187+
return !(p.required || p.id || p.nullable === false ||
1188+
p.allowNull === false || p['null'] === false);
1189+
}
1190+
11861191
MsSQL.prototype.propertySettingsSQL = function (model, prop) {
11871192
var p = this._models[model].properties[prop];
11881193
return this.columnDataType(model, prop) + ' ' +
1189-
(p.allowNull === false || p['null'] === false ? 'NOT NULL' : 'NULL');
1194+
(isNullable(p) ? 'NULL' : 'NOT NULL');
11901195
};
11911196

11921197
MsSQL.prototype.automigrate = function(models, cb) {

test/autoupdate.test.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('MS SQL server connector', function () {
3232
},
3333
"email": {
3434
"type": "String",
35-
"required": false,
35+
"required": true,
3636
"length": 40
3737
},
3838
"age": {
@@ -66,7 +66,7 @@ describe('MS SQL server connector', function () {
6666
"columnName": "EMAIL",
6767
"dataType": "nvarchar",
6868
"dataLength": 60,
69-
"nullable": "Y"
69+
"nullable": "YES"
7070
}
7171
},
7272
"firstName": {
@@ -92,6 +92,11 @@ describe('MS SQL server connector', function () {
9292
var names = props.map(function (p) {
9393
return p.columnName;
9494
});
95+
assert.equal(props[0].nullable, 'NO');
96+
assert.equal(props[1].nullable, 'YES');
97+
assert.equal(props[2].nullable, 'NO');
98+
assert.equal(props[3].nullable, 'YES');
99+
95100
assert.equal(names[0], 'id');
96101
assert.equal(names[1], 'name');
97102
assert.equal(names[2], 'email');

0 commit comments

Comments
 (0)