From bea845dd63f09ffe52e0d162247e915eda1a59bd Mon Sep 17 00:00:00 2001 From: Yannick Date: Thu, 31 Jul 2014 18:40:39 +0200 Subject: [PATCH] Add extra props on associations to delete When we need to delete some record on association, this driver use the $pullAll command. But the $pullAll requires an exact match. So, when the association has some extra properties, we need to include these properties in the pull object. --- lib/Drivers/DML/mongodb.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/Drivers/DML/mongodb.js b/lib/Drivers/DML/mongodb.js index 54d17fa6..a0d3a585 100644 --- a/lib/Drivers/DML/mongodb.js +++ b/lib/Drivers/DML/mongodb.js @@ -316,7 +316,13 @@ Driver.prototype.hasMany = function (Model, association) { pull[association.name] = []; for (var i = 0; i < Associations.length; i++) { - pull[association.name].push({ _id: Associations[i][association.model.id] }); + var props = {_id: Associations[i][association.model.id]}; + + if (Associations[i].extra !== undefined) { + props = _.merge(props, _.pick(Associations[i].extra, _.keys(association.props))); + } + + pull[association.name].push(props); } return db.update({