Fixing issue discovered by test with 1: syntax being required for relationship based filters.

This commit is contained in:
mike12345567 2024-05-21 18:39:46 +01:00
parent 0561ca6e1b
commit a5c5e2ffcd
1 changed files with 7 additions and 9 deletions

View File

@ -55,8 +55,8 @@ function buildInternalFieldList(
return fieldList return fieldList
} }
function tableInFilter(name: string) { function tableNameInFieldRegex(tableName: string) {
return `:${name}.` return new RegExp(`^${tableName}.|:${tableName}.`, "g")
} }
function cleanupFilters(filters: SearchFilters, tables: Table[]) { function cleanupFilters(filters: SearchFilters, tables: Table[]) {
@ -72,15 +72,13 @@ function cleanupFilters(filters: SearchFilters, tables: Table[]) {
// relationship, switch to table ID // relationship, switch to table ID
const tableRelated = tables.find( const tableRelated = tables.find(
table => table =>
table.originalName && key.includes(tableInFilter(table.originalName)) table.originalName &&
key.match(tableNameInFieldRegex(table.originalName))
) )
if (tableRelated && tableRelated.originalName) { if (tableRelated && tableRelated.originalName) {
filter[ // only replace the first, not replaceAll
key.replace( filter[key.replace(tableRelated.originalName, tableRelated._id!)] =
tableInFilter(tableRelated.originalName), filter[key]
tableInFilter(tableRelated._id!)
)
] = filter[key]
delete filter[key] delete filter[key]
} }
} }