Fixes #170 and maybe some other more subtle problems regarding soft removes not cascading properly, orphaning objects

This commit is contained in:
Stefan Zermatten
2018-11-13 10:07:55 +02:00
parent 3b669fd2f9
commit 56f1bd2829

View File

@@ -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);
}); });
}); });