Merge pull request #1492 from NextFaze/fix/1486-null-data

Allow passing null to base model ctor
This commit is contained in:
Miroslav Bajtoš 2017-10-04 12:14:55 +02:00 committed by GitHub
commit 3a6ddf927d
2 changed files with 12 additions and 1 deletions

View File

@ -74,7 +74,7 @@ ModelBaseClass.prototype._initProperties = function(data, options) {
var self = this; var self = this;
var ctor = this.constructor; var ctor = this.constructor;
if (typeof data !== 'undefined' && data.constructor && if (typeof data !== 'undefined' && data !== null && data.constructor &&
typeof (data.constructor) !== 'function') { typeof (data.constructor) !== 'function') {
throw new Error(g.f('Property name "{{constructor}}" is not allowed in %s data', ctor.modelName)); throw new Error(g.f('Property name "{{constructor}}" is not allowed in %s data', ctor.modelName));
} }

View File

@ -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() { describe('model option persistUndefinedAsNull', function() {
var TestModel, isStrict; var TestModel, isStrict;
before(function(done) { before(function(done) {