From 7b389180c7a16d537142cb214332be07617de076 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Tue, 16 Feb 2021 17:21:34 +0000 Subject: [PATCH] Fixing an issue with complex relationships that are heavily intra-related. --- packages/server/src/api/controllers/row.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/server/src/api/controllers/row.js b/packages/server/src/api/controllers/row.js index 078e4b722f..4f195ad4e8 100644 --- a/packages/server/src/api/controllers/row.js +++ b/packages/server/src/api/controllers/row.js @@ -387,8 +387,13 @@ exports.fetchEnrichedRow = async function(ctx) { for (let fieldName of Object.keys(table.schema)) { let field = table.schema[fieldName] if (field.type === FieldTypes.LINK) { - row[fieldName] = linkedRows.filter( - linkRow => linkRow.tableId === field.tableId + // find the links that pertain to this field, get their indexes + const linkIndexes = linkVals + .filter(link => link.fieldName === fieldName) + .map(link => linkVals.indexOf(link)) + // find the rows that the links state are linked to this field + row[fieldName] = linkedRows.filter((linkRow, index) => + linkIndexes.includes(index) ) } }