Keep dirty state for cached objects
This commit is contained in:
parent
8b720c30f8
commit
4d7b813953
|
@ -148,6 +148,7 @@ AbstractClass.find = function find(id, cb) {
|
|||
if (data) {
|
||||
if (this.cache[data.id]) {
|
||||
obj = this.cache[data.id];
|
||||
substractDirtyAttributes(obj, data);
|
||||
this.call(obj, data);
|
||||
} else {
|
||||
obj = new this(data);
|
||||
|
@ -182,11 +183,7 @@ AbstractClass.all = function all(params, cb) {
|
|||
if (constr.cache[d.id]) {
|
||||
obj = constr.cache[d.id];
|
||||
// keep dirty attributes untouthed (remove from dataset)
|
||||
Object.keys(obj.toObject()).forEach(function (attr) {
|
||||
if (attr in d && obj.propertyChanged(attr)) {
|
||||
delete d[attr];
|
||||
}
|
||||
});
|
||||
substractDirtyAttributes(obj, d);
|
||||
constr.call(obj, d);
|
||||
} else {
|
||||
obj = new constr(d);
|
||||
|
@ -199,6 +196,14 @@ AbstractClass.all = function all(params, cb) {
|
|||
});
|
||||
};
|
||||
|
||||
function substractDirtyAttributes(object, data) {
|
||||
Object.keys(object.toObject()).forEach(function (attr) {
|
||||
if (attr in data && object.propertyChanged(attr)) {
|
||||
delete data[attr];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
AbstractClass.destroyAll = function destroyAll(cb) {
|
||||
this.schema.adapter.destroyAll(this.modelName, function (err) {
|
||||
if (!err) {
|
||||
|
|
Loading…
Reference in New Issue