Merge pull request #17 from strongloop/schemaless-save

Make sure schemaless property value is honored over __data
This commit is contained in:
Raymond Feng 2013-10-04 14:28:38 -07:00
commit 89765ab18b
2 changed files with 16 additions and 1 deletions

View File

@ -226,7 +226,7 @@ ModelBaseClass.prototype.toObject = function (onlySchema) {
if (schemaLess) { if (schemaLess) {
Object.keys(self.__data).forEach(function (attr) { Object.keys(self.__data).forEach(function (attr) {
if (!data.hasOwnProperty(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) { if(val !== undefined && val!== null && val.toObject) {
data[attr] = val.toObject(!schemaLess); data[attr] = val.toObject(!schemaLess);
} else { } else {

View File

@ -369,6 +369,21 @@ describe('DataSource define model', function () {
done(null, User); 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);
});
});
});
}); });