From 0e348b0333b57e9e5f4a99fe8c8bc2d18f1f5994 Mon Sep 17 00:00:00 2001 From: Fabien Franzen Date: Fri, 15 Aug 2014 18:51:19 +0200 Subject: [PATCH] Fixed duplicate code --- lib/relation-definition.js | 44 -------------------------------------- 1 file changed, 44 deletions(-) diff --git a/lib/relation-definition.js b/lib/relation-definition.js index c71c9184..e11b28bc 100644 --- a/lib/relation-definition.js +++ b/lib/relation-definition.js @@ -1696,50 +1696,6 @@ EmbedsMany.prototype.embeddedList = function(modelInstance) { return embeddedList; }; -EmbedsMany.prototype.prepareEmbeddedInstance = function(inst) { - if (inst && inst.triggerParent !== 'function') { - var self = this; - var relationName = this.definition.name; - var modelInstance = this.modelInstance; - inst.triggerParent = function(actionName, callback) { - if (actionName === 'save' || actionName === 'destroy') { - var embeddedList = self.embeddedList(); - if (actionName === 'destroy') { - var index = embeddedList.indexOf(inst); - if (index > -1) embeddedList.splice(index, 1); - } - modelInstance.updateAttribute(relationName, - embeddedList, function(err, modelInst) { - callback(err, err ? null : modelInst); - }); - } else { - process.nextTick(callback); - } - }; - var originalTrigger = inst.trigger; - inst.trigger = function(actionName, work, data, callback) { - if (typeof work === 'function') { - var originalWork = work; - work = function(next) { - originalWork.call(this, function(done) { - inst.triggerParent(actionName, function(err, inst) { - next(done); // TODO [fabien] - error handling? - }); - }); - }; - } - originalTrigger.call(this, actionName, work, data, callback); - }; - } -}; - -EmbedsMany.prototype.embeddedList = function(modelInstance) { - modelInstance = modelInstance || this.modelInstance; - var embeddedList = modelInstance[this.definition.name] || []; - embeddedList.forEach(this.prepareEmbeddedInstance.bind(this)); - return embeddedList; -}; - EmbedsMany.prototype.related = function(receiver, scopeParams, condOrRefresh, cb) { var modelTo = this.definition.modelTo; var modelInstance = this.modelInstance;