Merge branch 'master' into juggler-tidyup

Conflicts:
	lib/model.js
This commit is contained in:
Raymond Feng 2013-10-04 14:32:51 -07:00
commit 24d87976e8
2 changed files with 17 additions and 2 deletions

View File

@ -226,7 +226,7 @@ ModelBaseClass.prototype.toObject = function (onlySchema) {
if (schemaLess) { if (schemaLess) {
Object.keys(self.__data).forEach(function (propertyName) { Object.keys(self.__data).forEach(function (propertyName) {
if (!data.hasOwnProperty(propertyName)) { if (!data.hasOwnProperty(propertyName)) {
var val = self.__data[propertyName]; var val = self.hasOwnProperty(propertyName) ? self[propertyName] : self.__data[propertyName];
if(val !== undefined && val!== null && val.toObject) { if(val !== undefined && val!== null && val.toObject) {
data[propertyName] = val.toObject(!schemaLess); data[propertyName] = val.toObject(!schemaLess);
} else { } else {
@ -290,4 +290,4 @@ ModelBaseClass.mixin = function(anotherClass, options) {
}; };
jutil.mixin(ModelBaseClass, Hookable); jutil.mixin(ModelBaseClass, Hookable);
jutil.mixin(ModelBaseClass, validations.Validatable); jutil.mixin(ModelBaseClass, validations.Validatable);

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);
});
});
});
}); });