diff --git a/packages/server/src/sdk/app/rows/queryUtils.ts b/packages/server/src/sdk/app/rows/queryUtils.ts index 9fa72e84d7..20e6af4d67 100644 --- a/packages/server/src/sdk/app/rows/queryUtils.ts +++ b/packages/server/src/sdk/app/rows/queryUtils.ts @@ -31,14 +31,10 @@ export const removeInvalidFilters = ( const filter = result[filterKey] for (const columnKey of Object.keys(filter)) { - if ( - !validFields - .map(f => f.toLowerCase()) - .includes(columnKey.toLowerCase()) && - !validFields - .map(f => f.toLowerCase()) - .includes(db.removeKeyNumbering(columnKey).toLowerCase()) - ) { + const possibleKeys = [columnKey, db.removeKeyNumbering(columnKey)].map( + c => c.toLowerCase() + ) + if (!validFields.some(f => possibleKeys.includes(f.toLowerCase()))) { delete filter[columnKey] } } diff --git a/packages/server/src/sdk/app/rows/tests/queryUtils.spec.ts b/packages/server/src/sdk/app/rows/tests/queryUtils.spec.ts index f249a8f91e..4970e83685 100644 --- a/packages/server/src/sdk/app/rows/tests/queryUtils.spec.ts +++ b/packages/server/src/sdk/app/rows/tests/queryUtils.spec.ts @@ -145,5 +145,38 @@ describe("query utils", () => { }, }) }) + + it("handles relationship filters", () => { + const prefixedFilters: SearchFilters = { + $or: { + conditions: [ + { equal: { "1:other.one": "foo" } }, + { + equal: { + "2:other.one": "foo2", + "3:other.two": "bar", + "4:other.three": "baz", + }, + }, + { equal: { "another.three": "baz2" } }, + ], + }, + } + + const result = removeInvalidFilters(prefixedFilters, [ + "other.one", + "other.two", + "another.three", + ]) + expect(result).toEqual({ + $or: { + conditions: [ + { equal: { "1:other.one": "foo" } }, + { equal: { "2:other.one": "foo2", "3:other.two": "bar" } }, + { equal: { "another.three": "baz2" } }, + ], + }, + }) + }) }) })