Skip to content

Commit

Permalink
Merge pull request #1492 from NextFaze/fix/1486-null-data
Browse files Browse the repository at this point in the history
Allow passing null to base model ctor
  • Loading branch information
bajtos committed Oct 4, 2017
2 parents d213c83 + 99cea38 commit 3a6ddf9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/model.js
Expand Up @@ -74,7 +74,7 @@ ModelBaseClass.prototype._initProperties = function(data, options) {
var self = this;
var ctor = this.constructor;

if (typeof data !== 'undefined' && data.constructor &&
if (typeof data !== 'undefined' && data !== null && data.constructor &&
typeof (data.constructor) !== 'function') {
throw new Error(g.f('Property name "{{constructor}}" is not allowed in %s data', ctor.modelName));
}
Expand Down
11 changes: 11 additions & 0 deletions test/datatype.test.js
Expand Up @@ -170,6 +170,17 @@ describe('datatypes', function() {
});
});

it('handles null data', (done) => {
db = getSchema();
Model = db.define('MyModel', {
data: {type: 'string'},
});
db.automigrate(['Model'], function() {
let a = new Model(null);
done();
});
});

describe('model option persistUndefinedAsNull', function() {
var TestModel, isStrict;
before(function(done) {
Expand Down

0 comments on commit 3a6ddf9

Please sign in to comment.