Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions lib/waterline/methods/add-to-collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,11 +349,16 @@ module.exports = function addToCollection(/* targetRecordIds, collectionAttrName
// through table mapping that was generated by Waterline-Schema.
else if (_.has(Object.getPrototypeOf(WLChild), 'throughTable')) {
childReference = WLChild.throughTable[WLModel.identity + '.' + query.collectionAttrName];
_.each(WLChild.throughTable, function(rhs, key) {
if (key !== WLModel.identity + '.' + query.collectionAttrName) {
parentReference = rhs;
}
});

parentReference = WLModel.identity;

// this code assumed that there would be only 2 associations on the through table
// but in some projects there are multiple
// _.each(WLChild.throughTable, function(rhs, key) {
// if (key !== WLModel.identity + '.' + query.collectionAttrName) {
// parentReference = rhs;
// }
// });
}

// Find the child reference in a junction table
Expand Down
15 changes: 10 additions & 5 deletions lib/waterline/methods/replace-collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,16 @@ module.exports = function replaceCollection(/* targetRecordIds?, collectionAttrN
// through table mapping that was generated by Waterline-Schema.
else if (_.has(Object.getPrototypeOf(WLChild), 'throughTable')) {
childReference = WLChild.throughTable[WLModel.identity + '.' + query.collectionAttrName];
_.each(WLChild.throughTable, function(rhs, key) {
if (key !== WLModel.identity + '.' + query.collectionAttrName) {
parentReference = rhs;
}
});

// should be safe to assume that the parentReference is indeed the main model here
parentReference = WLModel.identity;

// this code assumed that there would be only 2 associations on the through table (as stated above)
// _.each(WLChild.throughTable, function(rhs, key) {
// if (key !== WLModel.identity + '.' + query.collectionAttrName) {
// parentReference = rhs;
// }
// });
}//>-


Expand Down