Skip to content

Commit 591c7e5

Browse files
committed
update to partial saves
1 parent 779f3af commit 591c7e5

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

lib/model.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,21 @@ Model = this.Model = Class({
3232
_diff: function(){
3333
var keys = Object.keys(this.__doc),
3434
casters = Object.keys(this._casters),
35+
arrs = Object.keys(this._arrays),
3536
exclude = {};
3637

3738
for(var i = 0, l = casters.length; i < l; i++){
3839
this._partials[casters[i]] = JSON.stringify(this._get(casters[i]));
3940
}
4041

4142
for(var i = 0, l = keys.length; i < l; i++){
42-
this._partials[keys[i]] = JSON.stringify(this.__doc[keys[i]]);
43+
this._partials[keys[i]] = JSON.stringify(this.__doc[keys[i]]);
44+
}
45+
46+
for(var i = 0, l = arrs.length; i < l; i++){
47+
if(!this._partials[arrs[i]]){
48+
this._partials[arrs[i]] = JSON.stringify(this.__doc[keys[i]]);
49+
}
4350
}
4451
},
4552

@@ -51,9 +58,10 @@ Model = this.Model = Class({
5158
_parent = _parent || this;
5259
var keys = Object.getOwnPropertyNames(doc);
5360
keys.forEach(function(i){
54-
if (_parent[i] && typeof(_parent[i] == 'object') && !(_parent[i] instanceof Array)) this.merge(doc[i], _parent[i]);
61+
if (_parent[i] && typeof _parent[i] == 'object' && !(_parent[i] instanceof Array)) this.merge(doc[i], _parent[i]);
5562
else _parent[i] = doc[i];
5663
}, this);
64+
return this;
5765
},
5866

5967
_set: function(path, value, internal){
@@ -296,7 +304,8 @@ _define = function(proto, key, value){
296304
if(Object.prototype.toString.call(prop) == '[object Object]'){
297305
for(field in prop){
298306
if(prop[field] instanceof Array){
299-
_arr[(path ? path + '.' : '') + field] = true;
307+
p = (path ? path + '.' : '') + field;
308+
_arr[p] = true;
300309
if(!prop[field].length) _ret[field] = [];
301310
else if(prop[field][0] instanceof Array) _ret[field] = [];
302311
else _ret[field] = _compileProperties(prop[field],_arr,p);

0 commit comments

Comments
 (0)