Merge pull request #1492 from NextFaze/fix/1486-null-data
Allow passing null to base model ctor
This commit is contained in:
commit
3a6ddf927d
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue