From ec1efc856ec355229fcb48babd08dc26a758d575 Mon Sep 17 00:00:00 2001 From: adrinr Date: Wed, 22 Feb 2023 14:59:42 +0100 Subject: [PATCH] Handle link fields --- .../src/api/controllers/row/ExternalRequest.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/server/src/api/controllers/row/ExternalRequest.ts b/packages/server/src/api/controllers/row/ExternalRequest.ts index 56e54e299e..a262df8d69 100644 --- a/packages/server/src/api/controllers/row/ExternalRequest.ts +++ b/packages/server/src/api/controllers/row/ExternalRequest.ts @@ -177,9 +177,14 @@ function getEndpoint(tableId: string | undefined, operation: string) { function basicProcessing(row: Row, table: Table): Row { const thisRow: Row = {} // filter the row down to what is actually the row (not joined) - for (let fieldName of Object.keys(table.schema)) { + for (let field of Object.values(table.schema)) { + const fieldName = field.name + const pathValue = row[`${table.name}.${fieldName}`] - const value = pathValue != null ? pathValue : row[fieldName] + const value = + pathValue != null || field.type === FieldTypes.LINK + ? pathValue + : row[fieldName] // all responses include "select col as table.col" so that overlaps are handled if (value != null) { thisRow[fieldName] = value @@ -572,11 +577,18 @@ export class ExternalRequest { if (!linkTable || !linkPrimary) { return } + + const linkSecondary = + linkTable?.primary && + linkTable?.primary?.length > 1 && + linkTable?.primary[1] + const rows = related[key]?.rows || [] const found = rows.find( (row: { [key: string]: any }) => row[linkPrimary] === relationship.id || - row[linkPrimary] === body?.[linkPrimary] + (row[linkPrimary] === body?.[linkPrimary] && + (!linkSecondary || row[linkSecondary] === body?.[linkSecondary])) ) const operation = isUpdate ? Operation.UPDATE : Operation.CREATE if (!found) {