From 776f176f5c7b0ca66afea5dabb51463d597a9615 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Fri, 30 Jul 2021 18:49:36 +0100 Subject: [PATCH] Fix for issue #2167, the foreign key was not being set correctly in all scenarios for the from table in SQL relationships, our test data happened to hide this fact due to the foreign key and the key in from table having the same name. --- .../CreateEditRelationship.svelte | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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 9a9b8b20b1..33ca4608ff 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 @@ -158,10 +158,16 @@ fieldName: fromTable.primary[0], } } else { + // the relateFrom.fieldName should remain the same, as it is the foreignKey in the other + // table, this is due to the way that budibase represents relationships, the fieldName in a + // link column schema is the column linked to (FK in this case). The foreignKey column is + // essentially what is linked to in the from table, this is unique to SQL as this isn't a feature + // of Budibase internal tables. + // Essentially this means the fieldName is what we are linking to in the other table, and the + // foreignKey is what is linking out of the current table. relateFrom = { ...relateFrom, - foreignKey: relateFrom.fieldName, - fieldName: fromTable.primary[0], + foreignKey: fromTable.primary[0], } relateTo = { ...relateTo,