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) {
Object.keys(self.__data).forEach(function (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) {
data[propertyName] = val.toObject(!schemaLess);
} else {

View File

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