diff --git a/lib/model.js b/lib/model.js index 9c7f48f3..2e69d3e0 100644 --- a/lib/model.js +++ b/lib/model.js @@ -226,7 +226,7 @@ ModelBaseClass.prototype.toObject = function (onlySchema) { if (schemaLess) { Object.keys(self.__data).forEach(function (attr) { if (!data.hasOwnProperty(attr)) { - var val = self.__data[attr]; + var val = self.hasOwnProperty(attr) ? self[attr] : self.__data[attr]; if(val !== undefined && val!== null && val.toObject) { data[attr] = val.toObject(!schemaLess); } else { diff --git a/test/loopback-dl.test.js b/test/loopback-dl.test.js index 53d91a74..9dba1254 100644 --- a/test/loopback-dl.test.js +++ b/test/loopback-dl.test.js @@ -369,6 +369,21 @@ describe('DataSource define model', function () { done(null, User); }); + + it('should change the property value for save if strict=false', function (done) { + var ds = new DataSource('memory');// define models + var Post = ds.define('Post'); + + Post.create({price: 900}, function(err, post) { + assert.equal(post.price, 900); + post.price = 1000; + post.save(function(err, result) { + assert.equal(1000, result.price); + done(err, result); + }); + }); + }); + });