From 09a312b098abbc5d6453232db2337e84683b8e65 Mon Sep 17 00:00:00 2001 From: Scott Gress Date: Mon, 23 Jan 2017 08:07:12 -0600 Subject: [PATCH] Update method by which cacheKey for many-to-many-through queries is derived fixes https://github.com/balderdashy/sails/issues/3946 --- lib/waterline/model/lib/associationMethods/add.js | 2 +- lib/waterline/model/lib/associationMethods/remove.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/waterline/model/lib/associationMethods/add.js b/lib/waterline/model/lib/associationMethods/add.js index 184c6c349..d7d36d766 100644 --- a/lib/waterline/model/lib/associationMethods/add.js +++ b/lib/waterline/model/lib/associationMethods/add.js @@ -295,7 +295,7 @@ Add.prototype.createManyToMany = function(collection, attribute, pk, key, cb) { // If this is a throughTable, look into the meta data cache for what key to use if (collectionAttributes.throughTable) { - var cacheKey = collectionAttributes.throughTable[attribute.on + '.' + key] || collectionAttributes.throughTable[attribute.via + '.' + key]; + var cacheKey = collectionAttributes.throughTable[self.collection.adapter.identity + '.' + key] || collectionAttributes.throughTable[attribute.via + '.' + key]; if (!cacheKey) { return cb(new Error('Unable to find the proper cache key in the through table definition')); } diff --git a/lib/waterline/model/lib/associationMethods/remove.js b/lib/waterline/model/lib/associationMethods/remove.js index 7f46d856c..f1acd0634 100644 --- a/lib/waterline/model/lib/associationMethods/remove.js +++ b/lib/waterline/model/lib/associationMethods/remove.js @@ -233,7 +233,7 @@ Remove.prototype.removeManyToMany = function(collection, attribute, pk, key, cb) // If this is a throughTable, look into the meta data cache for what key to use if (collectionAttributes.throughTable) { - var cacheKey = collectionAttributes.throughTable[attribute.on + '.' + key] || collectionAttributes.throughTable[attribute.via + '.' + key]; + var cacheKey = collectionAttributes.throughTable[self.collection.adapter.identity + '.' + key] || collectionAttributes.throughTable[attribute.via + '.' + key]; if (!cacheKey) { return cb(new Error('Unable to find the proper cache key in the through table definition')); }