Skip to content

Commit

Permalink
Allow passing null to base model ctor
Browse files Browse the repository at this point in the history
  • Loading branch information
zbarbuto committed Sep 28, 2017
1 parent d213c83 commit 99cea38
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 99cea38

Please sign in to comment.