diff --git a/packages/server/src/tests/utilities/TestConfiguration.ts b/packages/server/src/tests/utilities/TestConfiguration.ts index 50aec9afc7..cec8c8aa12 100644 --- a/packages/server/src/tests/utilities/TestConfiguration.ts +++ b/packages/server/src/tests/utilities/TestConfiguration.ts @@ -54,6 +54,7 @@ import { FieldType, RelationshipType, CreateViewRequest, + RelationshipFieldMetadata, } from "@budibase/types" import API from "./api" @@ -587,7 +588,7 @@ class TestConfiguration { tableId: this.table._id!, name: link, relationshipType, - } + } as RelationshipFieldMetadata } if (this.datasource && !tableConfig.sourceId) { diff --git a/packages/types/src/documents/app/table/schema.ts b/packages/types/src/documents/app/table/schema.ts index 0e4837bc50..5af5b9c6d3 100644 --- a/packages/types/src/documents/app/table/schema.ts +++ b/packages/types/src/documents/app/table/schema.ts @@ -19,17 +19,29 @@ interface BaseRelationshipFieldMetadata extends Omit { type: FieldType.LINK main?: boolean - fieldName?: string + fieldName: string tableId: string subtype?: Omit } -export interface ManyToManyRelationshipFieldMetadata - extends BaseRelationshipFieldMetadata { - relationshipType: RelationshipType.MANY_TO_MANY - through?: string - throughFrom?: string - throughTo?: string -} + +// External tables use junction tables, internal tables don't require them +type ManyToManyJunctionTableMetadata = + | { + through: string + throughFrom: string + throughTo: string + } + | { + through?: never + throughFrom?: never + throughTo?: never + } + +export type ManyToManyRelationshipFieldMetadata = + BaseRelationshipFieldMetadata & { + relationshipType: RelationshipType.MANY_TO_MANY + } & ManyToManyJunctionTableMetadata + export interface OneToManyRelationshipFieldMetadata extends BaseRelationshipFieldMetadata { relationshipType: RelationshipType.ONE_TO_MANY