Make sure falsy value is kept for properties not predefined

This commit is contained in:
Raymond Feng 2014-08-21 13:47:09 -07:00
parent 07e65d6618
commit fcd8ed984c
2 changed files with 4 additions and 2 deletions

View File

@ -151,7 +151,8 @@ ModelBaseClass.prototype._initProperties = function (data, options) {
} else {
// Un-managed property
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') {
throw new Error('Unknown property: ' + p);
}

View File

@ -28,12 +28,13 @@ describe('ModelBuilder define model', function () {
modelBuilder.models.should.be.a('object').and.have.property('User', 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.should.be.a('object').and.have.property('name', 'Joe');
user.should.have.property('name', 'Joe');
user.should.have.property('age', 20);
user.should.have.property('xyz', false);
user.should.not.have.property('bio');
done(null, User);
});