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 (data) {
|
||||||
if (this.cache[data.id]) {
|
if (this.cache[data.id]) {
|
||||||
obj = this.cache[data.id];
|
obj = this.cache[data.id];
|
||||||
|
substractDirtyAttributes(obj, data);
|
||||||
this.call(obj, data);
|
this.call(obj, data);
|
||||||
} else {
|
} else {
|
||||||
obj = new this(data);
|
obj = new this(data);
|
||||||
|
@ -182,11 +183,7 @@ AbstractClass.all = function all(params, cb) {
|
||||||
if (constr.cache[d.id]) {
|
if (constr.cache[d.id]) {
|
||||||
obj = constr.cache[d.id];
|
obj = constr.cache[d.id];
|
||||||
// keep dirty attributes untouthed (remove from dataset)
|
// keep dirty attributes untouthed (remove from dataset)
|
||||||
Object.keys(obj.toObject()).forEach(function (attr) {
|
substractDirtyAttributes(obj, d);
|
||||||
if (attr in d && obj.propertyChanged(attr)) {
|
|
||||||
delete d[attr];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
constr.call(obj, d);
|
constr.call(obj, d);
|
||||||
} else {
|
} else {
|
||||||
obj = new constr(d);
|
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) {
|
AbstractClass.destroyAll = function destroyAll(cb) {
|
||||||
this.schema.adapter.destroyAll(this.modelName, function (err) {
|
this.schema.adapter.destroyAll(this.modelName, function (err) {
|
||||||
if (!err) {
|
if (!err) {
|
||||||
|
|
Loading…
Reference in New Issue