Finally fix notContains tests.

This commit is contained in:
Sam Rose 2024-10-23 16:22:07 +01:00
parent 309506adab
commit aaf4022f25
No known key found for this signature in database
2 changed files with 25 additions and 15 deletions

View File

@ -713,7 +713,11 @@ class InternalBuilder {
return q return q
} }
q = addModifiers(q).where(subQuery => { q = q.where(subQuery => {
if (mode === filters?.notContains) {
subQuery = subQuery.not
}
subQuery.where(subSubQuery => { subQuery.where(subSubQuery => {
for (const elem of value) { for (const elem of value) {
if (mode === filters?.containsAny) { if (mode === filters?.containsAny) {
@ -733,13 +737,19 @@ class InternalBuilder {
`%${lower}%` `%${lower}%`
) )
} }
})
})
if (mode === filters?.notContains) { return subSubQuery
// @ts-expect-error knex types are wrong, raw is fine here })
q.or.whereNull(this.rawQuotedIdentifier(key))
} 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 return q
}) })

View File

@ -48,13 +48,13 @@ import { generateRowIdField } from "../../../integrations/utils"
import { cloneDeep } from "lodash/fp" import { cloneDeep } from "lodash/fp"
describe.each([ describe.each([
// ["in-memory", undefined], ["in-memory", undefined],
// ["lucene", undefined], ["lucene", undefined],
// ["sqs", undefined], ["sqs", undefined],
// [DatabaseName.POSTGRES, getDatasource(DatabaseName.POSTGRES)], [DatabaseName.POSTGRES, getDatasource(DatabaseName.POSTGRES)],
// [DatabaseName.MYSQL, getDatasource(DatabaseName.MYSQL)], [DatabaseName.MYSQL, getDatasource(DatabaseName.MYSQL)],
// [DatabaseName.SQL_SERVER, getDatasource(DatabaseName.SQL_SERVER)], [DatabaseName.SQL_SERVER, getDatasource(DatabaseName.SQL_SERVER)],
// [DatabaseName.MARIADB, getDatasource(DatabaseName.MARIADB)], [DatabaseName.MARIADB, getDatasource(DatabaseName.MARIADB)],
[DatabaseName.ORACLE, getDatasource(DatabaseName.ORACLE)], [DatabaseName.ORACLE, getDatasource(DatabaseName.ORACLE)],
])("search (%s)", (name, dsProvider) => { ])("search (%s)", (name, dsProvider) => {
const isSqs = name === "sqs" const isSqs = name === "sqs"
@ -691,7 +691,7 @@ describe.each([
]) ])
}) })
it.only("should not match the session user id in a multi user field", async () => { it("should not match the session user id in a multi user field", async () => {
await expectQuery({ await expectQuery({
notContains: { multi_user: ["{{ [user]._id }}"] }, notContains: { multi_user: ["{{ [user]._id }}"] },
notEmpty: { multi_user: true }, notEmpty: { multi_user: true },