feat: add logical not query operator#16067
feat: add logical not query operator#16067ollieabbey wants to merge 1 commit intopayloadcms:mainfrom
Conversation
| // @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve | ||
| and?: Where[] | ||
| // @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve | ||
| not?: Where |
There was a problem hiding this comment.
We should change this to _not in case if someone has field not defined so it won't be breaking for them. We explicitly say that fields that start with _ are internal
| @@ -0,0 +1,256 @@ | |||
| import type { Payload } from 'payload' | |||
There was a problem hiding this comment.
I would like this test to exist in the database folder. However, you can create there a subfolder so you have a separate config from database like for example here https://github.com/payloadcms/payload/blob/main/test/database/migrate-to-blocks-as-json/config.ts
| it('should support not operator with nested relationship properties', async () => { | ||
| const { docs } = await payload.find({ | ||
| collection: postsSlug, | ||
| where: { | ||
| not: { | ||
| 'category.name': { | ||
| equals: 'cat1', | ||
| }, | ||
| }, | ||
| }, | ||
| }) |
There was a problem hiding this comment.
Need some coverage with versions too.
payload.findVersions
payload.find({ draft: true }) - internally uses db.queryDrafts and I think this might actually fail
and with access control, ensure
not: { field: { equals } } cannot be queried if the user does not have access to field
What?
Add a
notoperator towherequeries that allows you to negate the child query, alongsideandandor.Why?
Allows you to check the inverse of something. While this is already possible with some operators (e.g.
equalshasnot_equals), I don't think it's possible to invert more complex conditions.E.g. say there is an array field 'categories', we can currently query that the array contains a value
But now you can invert that to find documents that don't have the category news
How?
Using the existing drizzle & mongoose apis for negating a query (mongoose uses
norrather thannot, asnotonly accepts a field level expression, whilenoraccepts a full filter expression).