From fcd8ed984cd701195f77177a7184cd135ea44786 Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Thu, 21 Aug 2014 13:47:09 -0700 Subject: [PATCH] Make sure falsy value is kept for properties not predefined --- lib/model.js | 3 ++- test/loopback-dl.test.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/model.js b/lib/model.js index ee51fa26..069d39c1 100644 --- a/lib/model.js +++ b/lib/model.js @@ -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); } diff --git a/test/loopback-dl.test.js b/test/loopback-dl.test.js index 9d2d42d2..972d7aab 100644 --- a/test/loopback-dl.test.js +++ b/test/loopback-dl.test.js @@ -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); });