Skip to content

Commit

Permalink
fix issue with many-to-many through with custom column names not bein…
Browse files Browse the repository at this point in the history
…g mapped correctly
  • Loading branch information
particlebanana committed Oct 27, 2016
1 parent 144f80a commit 1f4ff37
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/waterline/model/lib/associationMethods/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,12 @@ Add.prototype.createManyToMany = function(collection, attribute, pk, key, cb) {

// Grab the associated collection's primaryKey
var collectionAttributes = this.collection.waterline.schema[attribute.collection.toLowerCase()];
var associationKey = collectionAttributes.attributes[attribute.on].via;
var associationKeyAttr = collectionAttributes.attributes[attribute.on] || collectionAttributes.attributes[attribute.via];
var associationKey = associationKeyAttr.via;

// 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];
var cacheKey = collectionAttributes.throughTable[attribute.on + '.' + key] || collectionAttributes.throughTable[attribute.via + '.' + key];
if (!cacheKey) {
return cb(new Error('Unable to find the proper cache key in the through table definition'));
}
Expand Down
5 changes: 3 additions & 2 deletions lib/waterline/model/lib/associationMethods/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,12 @@ Remove.prototype.removeManyToMany = function(collection, attribute, pk, key, cb)

// Grab the associated collection's primaryKey
var collectionAttributes = this.collection.waterline.schema[attribute.collection.toLowerCase()];
var associationKey = collectionAttributes.attributes[attribute.on].via;
var associationKeyAttr = collectionAttributes.attributes[attribute.on] || collectionAttributes.attributes[attribute.via];
var associationKey = associationKeyAttr.via;

// 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];
var cacheKey = collectionAttributes.throughTable[attribute.on + '.' + key] || collectionAttributes.throughTable[attribute.via + '.' + key];
if (!cacheKey) {
return cb(new Error('Unable to find the proper cache key in the through table definition'));
}
Expand Down

0 comments on commit 1f4ff37

Please sign in to comment.