diff --git a/packages/server/src/api/controllers/table/index.ts b/packages/server/src/api/controllers/table/index.ts index 5e40f53d59..22c4e98524 100644 --- a/packages/server/src/api/controllers/table/index.ts +++ b/packages/server/src/api/controllers/table/index.ts @@ -91,8 +91,11 @@ export async function find(ctx: UserCtx) { const tableId = ctx.params.tableId const table = await sdk.tables.getTable(tableId) - let result = await sdk.tables.enrichRelationshipSchemas(table) - result = sdk.tables.enrichViewSchemas(result) + const enrichedSchema = await sdk.tables.enrichRelationshipSchema(table) + const result = sdk.tables.enrichViewSchemas({ + ...table, + schema: enrichedSchema, + }) ctx.body = result } diff --git a/packages/server/src/sdk/app/tables/getters.ts b/packages/server/src/sdk/app/tables/getters.ts index 78633feed5..ded7f5ef09 100644 --- a/packages/server/src/sdk/app/tables/getters.ts +++ b/packages/server/src/sdk/app/tables/getters.ts @@ -12,6 +12,7 @@ import { RelationshipFieldMetadata, Table, TableResponse, + TableSchema, TableSourceType, TableViewsResponse, } from "@budibase/types" @@ -144,9 +145,9 @@ export async function getTables(tableIds: string[]): Promise { return processTables(tables) } -export async function enrichRelationshipSchemas( +export async function enrichRelationshipSchema( table: Table -): Promise { +): Promise { const tableCache: Record = {} async function populateRelTableSchema(field: RelationshipFieldMetadata) { @@ -179,14 +180,14 @@ export async function enrichRelationshipSchemas( } } - const result: TableResponse = { ...table, schema: {}, views: {} } + const result: TableSchema = {} for (const fieldName of Object.keys(table.schema)) { const field = { ...table.schema[fieldName] } if (field.type === FieldType.LINK) { await populateRelTableSchema(field) } - result.schema[fieldName] = field + result[fieldName] = field } return result }