challenges: lots of misc. bug fixes

This commit is contained in:
Tyler Renelle
2013-10-29 20:37:22 -07:00
parent 6e71a76e22
commit d116ac7b81
6 changed files with 100 additions and 39 deletions
+7
View File
@@ -58,6 +58,8 @@ function removeDuplicates(doc){
}
}
// FIXME this isn't always triggered, since we sometimes use update() or findByIdAndUpdate()
// @see https://github.com/LearnBoost/mongoose/issues/964
GroupSchema.pre('save', function(next){
removeDuplicates(this);
this.memberCount = _.size(this.members);
@@ -69,6 +71,11 @@ GroupSchema.methods.toJSON = function(){
var doc = this.toObject();
removeDuplicates(doc);
doc._isMember = this._isMember;
// @see pre('save') comment above
this.memberCount = _.size(this.members);
this.challengeCount = _.size(this.challenges);
return doc;
}