diff --git a/lib/relation-definition.js b/lib/relation-definition.js index 567a0636..cd73fbc9 100644 --- a/lib/relation-definition.js +++ b/lib/relation-definition.js @@ -954,13 +954,14 @@ HasManyThrough.prototype.create = function create(data, done) { var fk2 = keys[1]; function createRelation(to, next) { - var d = {}; - d[fk1] = modelInstance[definition.keyFrom]; - d[fk2] = to[pk2]; + var d = {}, q = {}, filter = {where:q}; + d[fk1] = q[fk1] = modelInstance[definition.keyFrom]; + d[fk2] = q[fk2] = to[pk2]; definition.applyProperties(modelInstance, d); + definition.applyScope(modelInstance, filter); // Then create the through model - modelThrough.create(d, function (e, through) { + modelThrough.findOrCreate(filter, d, function (e, through) { if (e) { // Undo creation of the target model to.destroy(function () {