Make sure schemaless property value is honored over __data

This commit is contained in:
Raymond Feng 2013-09-18 16:34:52 -07:00
parent 77952d5e43
commit 1575c87caf
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);
});
});
});
}); });