Browse Source

Delete all activities related to a checklist when it is deleted

Ghassen Rjab 7 years ago
parent
commit
a579125a1f
1 changed files with 5 additions and 3 deletions
  1. 5 3
      models/checklists.js

+ 5 - 3
models/checklists.js

@@ -185,9 +185,11 @@ if (Meteor.isServer) {
   });
   });
 
 
   Checklists.before.remove((userId, doc) => {
   Checklists.before.remove((userId, doc) => {
-    const activity = Activities.findOne({ checklistId: doc._id });
-    if (activity) {
-      Activities.remove(activity._id);
+    const activities = Activities.find({ checklistId: doc._id });
+    if (activities) {
+      activities.forEach((activity) => {
+        Activities.remove(activity._id);
+      });
     }
     }
   });
   });
 }
 }