Fixes #170 and maybe some other more subtle problems regarding soft removes not cascading properly, orphaning objects
This commit is contained in:
@@ -145,17 +145,17 @@ var checkPermission = function(userId, charId){
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
var cascadeSoftRemove = function(id, removedWithId){
|
var cascadeSoftRemove = function(parentId, removedWithId){
|
||||||
_.each(childCollections, function(treeCollection){
|
_.each(childCollections, function(treeCollection){
|
||||||
treeCollection.update(
|
treeCollection.update(
|
||||||
{"parent.id": id},
|
{"parent.id": parentId},
|
||||||
{$set: {
|
{$set: {
|
||||||
removed: true,
|
removed: true,
|
||||||
removedWith: removedWithId,
|
removedWith: removedWithId,
|
||||||
}},
|
}},
|
||||||
{multi: true}
|
{multi: true}
|
||||||
);
|
);
|
||||||
treeCollection.find({"parent.id": id}).forEach(function(doc){
|
treeCollection.find({"parent.id": parentId, removed: true}).forEach(function(doc){
|
||||||
cascadeSoftRemove(doc._id, removedWithId);
|
cascadeSoftRemove(doc._id, removedWithId);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user