diff --git a/lib/waterline-schema/joinTables.js b/lib/waterline-schema/joinTables.js index d765e37..78d5b12 100644 --- a/lib/waterline-schema/joinTables.js +++ b/lib/waterline-schema/joinTables.js @@ -496,7 +496,7 @@ JoinTables.prototype.markCustomJoinTables = function(collection) { var throughPath = collection + '.' + attribute; var linkedAttrs = this.collections[linkedCollection].attributes; this.collections[linkedCollection].throughTable[throughPath] = _.find(_.keys(linkedAttrs), function(attr){ - return linkedAttrs[attr].references === attributes[attribute].collection.toLowerCase(); + return linkedAttrs[attr].references === attributes[attribute].collection.toLowerCase() && attributes[attribute].via !== attr; }); // Build up proper reference on the attribute