Make sure falsy value is kept for properties not predefined
This commit is contained in:
parent
07e65d6618
commit
fcd8ed984c
|
@ -151,7 +151,8 @@ ModelBaseClass.prototype._initProperties = function (data, options) {
|
||||||
} else {
|
} else {
|
||||||
// Un-managed property
|
// Un-managed property
|
||||||
if (strict === false || self.__cachedRelations[p]) {
|
if (strict === false || self.__cachedRelations[p]) {
|
||||||
self[p] = self.__data[p] = propVal || self.__cachedRelations[p];
|
self[p] = self.__data[p] =
|
||||||
|
(propVal !== undefined) ? propVal : self.__cachedRelations[p];
|
||||||
} else if (strict === 'throw') {
|
} else if (strict === 'throw') {
|
||||||
throw new Error('Unknown property: ' + p);
|
throw new Error('Unknown property: ' + p);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,12 +28,13 @@ describe('ModelBuilder define model', function () {
|
||||||
modelBuilder.models.should.be.a('object').and.have.property('User', User);
|
modelBuilder.models.should.be.a('object').and.have.property('User', User);
|
||||||
modelBuilder.definitions.should.be.a('object').and.have.property('User');
|
modelBuilder.definitions.should.be.a('object').and.have.property('User');
|
||||||
|
|
||||||
var user = new User({name: 'Joe', age: 20});
|
var user = new User({name: 'Joe', age: 20, xyz: false});
|
||||||
|
|
||||||
User.modelName.should.equal('User');
|
User.modelName.should.equal('User');
|
||||||
user.should.be.a('object').and.have.property('name', 'Joe');
|
user.should.be.a('object').and.have.property('name', 'Joe');
|
||||||
user.should.have.property('name', 'Joe');
|
user.should.have.property('name', 'Joe');
|
||||||
user.should.have.property('age', 20);
|
user.should.have.property('age', 20);
|
||||||
|
user.should.have.property('xyz', false);
|
||||||
user.should.not.have.property('bio');
|
user.should.not.have.property('bio');
|
||||||
done(null, User);
|
done(null, User);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue