From c5e52f7cbed1c7eceb03b1880cfb16323295d0d3 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 29 Sep 2023 14:02:45 +0200 Subject: [PATCH] Fix deleting one-2-many relationships --- .../src/api/controllers/row/ExternalRequest.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/server/src/api/controllers/row/ExternalRequest.ts b/packages/server/src/api/controllers/row/ExternalRequest.ts index 9ab96fba69..7a4f4c5a47 100644 --- a/packages/server/src/api/controllers/row/ExternalRequest.ts +++ b/packages/server/src/api/controllers/row/ExternalRequest.ts @@ -340,10 +340,16 @@ export class ExternalRequest { // one to many if (isOneSide(field)) { let id = row[key][0] - if (typeof row[key] === "string") { - id = decodeURIComponent(row[key]).match(/\[(.*?)\]/)?.[1] + if (id) { + if (typeof row[key] === "string") { + id = decodeURIComponent(row[key]).match(/\[(.*?)\]/)?.[1] + } + newRow[field.foreignKey || linkTablePrimary] = breakRowIdField(id)[0] + } else { + // + row[field.foreignKey || linkTablePrimary] = null + newRow[field.foreignKey || linkTablePrimary] = null } - newRow[field.foreignKey || linkTablePrimary] = breakRowIdField(id)[0] } // many to many else if (field.through) {