From a343805feecf822327e3a3f90a89e6133c0aabf6 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Fri, 1 Oct 2021 17:16:43 +0100 Subject: [PATCH] Fix for many to many relationships where the union table has arbituarily named foreign key constraint columns, an example has been provided in the scripts directory. --- .../CreateEditRelationship.svelte | 18 ++++++++ .../customer-categories/docker-compose.yml | 28 +++++++++++++ .../integrations/customer-categories/init.sql | 41 +++++++++++++++++++ .../integrations/customer-categories/reset.sh | 3 ++ .../api/controllers/row/ExternalRequest.ts | 16 ++++---- packages/server/src/definitions/common.ts | 2 + packages/server/src/definitions/datasource.ts | 2 + packages/server/src/integrations/base/sql.ts | 6 ++- 8 files changed, 107 insertions(+), 9 deletions(-) create mode 100644 packages/server/scripts/integrations/customer-categories/docker-compose.yml create mode 100644 packages/server/scripts/integrations/customer-categories/init.sql create mode 100755 packages/server/scripts/integrations/customer-categories/reset.sh diff --git a/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/CreateEditRelationship/CreateEditRelationship.svelte b/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/CreateEditRelationship/CreateEditRelationship.svelte index fbc2b401ef..583ca5e887 100644 --- a/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/CreateEditRelationship/CreateEditRelationship.svelte +++ b/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/CreateEditRelationship/CreateEditRelationship.svelte @@ -156,6 +156,8 @@ ...relateTo, through: through._id, fieldName: fromTable.primary[0], + throughFrom: relateFrom.throughTo, + throughTo: relateFrom.throughFrom, } } else { // the relateFrom.fieldName should remain the same, as it is the foreignKey in the other @@ -251,6 +253,22 @@ bind:error={errors.through} bind:value={fromRelationship.through} /> + {#if fromTable && toTable && through} + ($touched.toForeign = true)} + bind:error={errors.toForeign} + bind:value={fromRelationship.throughFrom} + /> + {/if} {:else if fromRelationship?.relationshipType && toTable}