Added cascading deletions

This commit is contained in:
Thaum
2015-03-04 10:17:32 +00:00
parent 88dbaccfc5
commit a5068f1bc2
10 changed files with 72 additions and 34 deletions

View File

@@ -19,3 +19,10 @@ Schemas.Buff = new SimpleSchema({
});
Buffs.attachSchema(Schemas.Buff);
Buffs.before.remove(function (userId, buff) {
Effects.find({sourceId: buff._id, type: "buff"}).forEach(function(effect){
Effects.remove(effect._id);
});
});

View File

@@ -433,7 +433,7 @@ Characters.helpers({
var mod = +getMod(this.attributeValue(attribute));
return 10 + mod;
},
xpLevel: function(){
var xp = this.experience();
var xpTable = [0, 300, 900, 2700, 6500, 14000, 23000, 34000, 48000, 64000,
@@ -455,7 +455,7 @@ Characters.helpers({
})
return level;
},
experience: function(){
var xp = 0;
Experiences.find({charId: this._id}, {fields: {value: 1}}).forEach(function(e){
@@ -464,3 +464,21 @@ Characters.helpers({
return xp;
}
});
//clean up all data related to that character before removing it
Characters.before.remove(function (userId, character) {
if(Meteor.isServer){
Actions .remove({charId: character._id});
Attacks .remove({charId: character._id});
Buffs .remove({charId: character._id});
Classes .remove({charId: character._id});
Effects .remove({charId: character._id});
Experience .remove({charId: character._id});
Features .remove({charId: character._id});
Notes .remove({charId: character._id});
Proficiencies .remove({charId: character._id});
SpellLists .remove({charId: character._id});
Items .remove({charId: character._id});
Containers .remove({charId: character._id});
}
});

View File

@@ -20,3 +20,9 @@ Features.helpers({
return evaluate(this.charId, this.uses);
}
});
Features.before.remove(function (userId, feature) {
Effects.find({sourceId: feature._id, type: "feature"}).forEach(function(effect){
Effects.remove(effect._id);
});
});

View File

@@ -22,3 +22,13 @@ SpellLists.helpers({
return num;
}
});
SpellLists.before.remove(function (userId, list) {
if(Meteor.isServer){
Spells.remove({listId: list._id});
} else {
Spells.find({listId: list._id}).forEach(function(spell){
Spells.remove(spell._id);
});
}
});