diff --git a/packages/backend-core/src/sql/sql.ts b/packages/backend-core/src/sql/sql.ts index 684f276145..8922ce055b 100644 --- a/packages/backend-core/src/sql/sql.ts +++ b/packages/backend-core/src/sql/sql.ts @@ -740,12 +740,12 @@ class InternalBuilder { return q } - return q.where(subQuery => { + q = q.where(subQuery => { if (mode === filters?.notContains) { subQuery = subQuery.not } - return subQuery.where(subSubQuery => { + subQuery = subQuery.where(subSubQuery => { for (const elem of value) { if (mode === filters?.containsAny) { subSubQuery = subSubQuery.or @@ -765,7 +765,15 @@ class InternalBuilder { ) } }) + if (mode === filters?.notContains) { + subQuery = subQuery.or.whereNull( + // @ts-expect-error knex types are wrong, raw is fine here + this.rawQuotedIdentifier(key) + ) + } + return subQuery }) + return q }) } } diff --git a/packages/server/src/api/routes/tests/search.spec.ts b/packages/server/src/api/routes/tests/search.spec.ts index b22b1545be..b319248ff7 100644 --- a/packages/server/src/api/routes/tests/search.spec.ts +++ b/packages/server/src/api/routes/tests/search.spec.ts @@ -2163,7 +2163,7 @@ describe.each([ }) }) - describe.only("multi user", () => { + describe("multi user", () => { let user1: User let user2: User