Skip to content

Commit

Permalink
fixed charId's being out of date after re-parenting
Browse files Browse the repository at this point in the history
  • Loading branch information
ThaumRystra committed May 11, 2015
1 parent e4600de commit 3f4dcc1
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion rpg-docs/lib/functions/parenting.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ var inheritParentProperties = function(doc, collection){
"Document's parent does not exist"
);
var handMeDowns = _.pick(parent, collection.inheritedKeys);
if (
_.contains(collection.inheritedKeys, "charId") &&
doc.parent.collection === "Characters"
){
handMeDowns.charId = doc.parent.id;
}
if (_.isEmpty(handMeDowns)) return;
collection.update(doc._id, {$set: handMeDowns});
};
Expand Down Expand Up @@ -77,8 +83,9 @@ makeChild = function(collection, inheritedKeys){
});

collection.after.update(function(userId, doc, fieldNames, modifier, options) {
if (modifier && modifier.$set && modifier.$set.parent){
if (modifier && modifier.$set && modifier.$set["parent.id"]){
//when we change parents, inherit its properties
console.log("re-inheriting")
inheritParentProperties(doc, collection);
}
});
Expand Down

0 comments on commit 3f4dcc1

Please sign in to comment.