From 5435028e7daff6844988d1a1cb51b4968e35776f Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Tue, 20 Aug 2024 12:13:37 +0100 Subject: [PATCH] Fix for cyclic relationships, getQueryableFields allowed relationships from other tables, which can't work. --- packages/server/src/sdk/app/rows/queryUtils.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/server/src/sdk/app/rows/queryUtils.ts b/packages/server/src/sdk/app/rows/queryUtils.ts index a5e78b2fb9..78cf64e184 100644 --- a/packages/server/src/sdk/app/rows/queryUtils.ts +++ b/packages/server/src/sdk/app/rows/queryUtils.ts @@ -59,14 +59,15 @@ export const getQueryableFields = async ( const extractTableFields = async ( table: Table, allowedFields: string[], - fromTables: string[] + fromTables: string[], + opts: { allowRelationships?: boolean } = { allowRelationships: true } ): Promise => { const result = [] for (const field of Object.keys(table.schema).filter( f => allowedFields.includes(f) && table.schema[f].visible !== false )) { const subSchema = table.schema[field] - if (subSchema.type === FieldType.LINK) { + if (opts.allowRelationships && subSchema.type === FieldType.LINK) { if (fromTables.includes(subSchema.tableId)) { // avoid circular loops continue @@ -76,7 +77,9 @@ export const getQueryableFields = async ( const relatedFields = await extractTableFields( relatedTable, Object.keys(relatedTable.schema), - [...fromTables, subSchema.tableId] + [...fromTables, subSchema.tableId], + // don't let it recurse back and forth between relationships + { allowRelationships: false } ) result.push(