From 3f4dcc146ab2360e4774f9b98d524e1b51dee35e Mon Sep 17 00:00:00 2001 From: Stefan Zermatten Date: Mon, 11 May 2015 17:10:28 +0200 Subject: [PATCH] fixed charId's being out of date after re-parenting --- rpg-docs/lib/functions/parenting.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/rpg-docs/lib/functions/parenting.js b/rpg-docs/lib/functions/parenting.js index 1d2beac40..ee6b11f35 100644 --- a/rpg-docs/lib/functions/parenting.js +++ b/rpg-docs/lib/functions/parenting.js @@ -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}); }; @@ -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); } });