Merge pull request #17 from strongloop/schemaless-save
Make sure schemaless property value is honored over __data
This commit is contained in:
commit
89765ab18b
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue