diff --git a/lib/model.js b/lib/model.js index ee30f1741..d9d65a09a 100644 --- a/lib/model.js +++ b/lib/model.js @@ -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)); } diff --git a/test/datatype.test.js b/test/datatype.test.js index c4c9c0b89..5cdb68cbc 100644 --- a/test/datatype.test.js +++ b/test/datatype.test.js @@ -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) {