diff --git a/packages/builder/src/components/backend/Datasources/CreateEditRelationship.svelte b/packages/builder/src/components/backend/Datasources/CreateEditRelationship.svelte index c8aaee0695..8a0bcce91e 100644 --- a/packages/builder/src/components/backend/Datasources/CreateEditRelationship.svelte +++ b/packages/builder/src/components/backend/Datasources/CreateEditRelationship.svelte @@ -195,7 +195,8 @@ throughTable, fromTable.primary[0], throughToKey - ), + ) || + errorChecker.differentColumns(throughFromKey, throughToKey), throughToKey: errorChecker.manyForeignKeySet(throughToKey) || errorChecker.manyTypeMismatch( diff --git a/packages/builder/src/components/backend/Datasources/relationshipErrors.js b/packages/builder/src/components/backend/Datasources/relationshipErrors.js index 2088a55b81..9fd30eaea2 100644 --- a/packages/builder/src/components/backend/Datasources/relationshipErrors.js +++ b/packages/builder/src/components/backend/Datasources/relationshipErrors.js @@ -3,6 +3,7 @@ import { RelationshipType } from "@budibase/types" const typeMismatch = "Column type of the foreign key must match the primary key" const columnBeingUsed = "Column name cannot be an existing column" const mustBeDifferentTables = "From/to/through tables must be different" +const mustBeDifferentColumns = "Foreign keys must be different" const primaryKeyNotSet = "Please pick the primary key" const throughNotNullable = "Ensure non-key columns are nullable or auto-generated" @@ -83,6 +84,11 @@ export class RelationshipErrorChecker { return error ? mustBeDifferentTables : null } + differentColumns(columnA, columnB) { + const error = columnA && columnB && columnA === columnB + return error ? mustBeDifferentColumns : null + } + columnBeingUsed(table, column, ogName) { return isColumnNameBeingUsed(table, column, ogName) ? columnBeingUsed : null }