From a5c5e2ffcdfcd9ecc13f15e0df1ef5b986ed662e Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Tue, 21 May 2024 18:39:46 +0100 Subject: [PATCH] Fixing issue discovered by test with 1: syntax being required for relationship based filters. --- packages/server/src/sdk/app/rows/search/sqs.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/server/src/sdk/app/rows/search/sqs.ts b/packages/server/src/sdk/app/rows/search/sqs.ts index c4dc408cac..ec3ac08c2e 100644 --- a/packages/server/src/sdk/app/rows/search/sqs.ts +++ b/packages/server/src/sdk/app/rows/search/sqs.ts @@ -55,8 +55,8 @@ function buildInternalFieldList( return fieldList } -function tableInFilter(name: string) { - return `:${name}.` +function tableNameInFieldRegex(tableName: string) { + return new RegExp(`^${tableName}.|:${tableName}.`, "g") } function cleanupFilters(filters: SearchFilters, tables: Table[]) { @@ -72,15 +72,13 @@ function cleanupFilters(filters: SearchFilters, tables: Table[]) { // relationship, switch to table ID const tableRelated = tables.find( table => - table.originalName && key.includes(tableInFilter(table.originalName)) + table.originalName && + key.match(tableNameInFieldRegex(table.originalName)) ) if (tableRelated && tableRelated.originalName) { - filter[ - key.replace( - tableInFilter(tableRelated.originalName), - tableInFilter(tableRelated._id!) - ) - ] = filter[key] + // only replace the first, not replaceAll + filter[key.replace(tableRelated.originalName, tableRelated._id!)] = + filter[key] delete filter[key] } }