payloadcms / payload

Payload is the open-source, fullstack Next.js framework, giving you instant backend superpowers. Get a full TypeScript backend and admin panel instantly. Use Payload as a headless CMS or for building powerful applications.
https://payloadcms.com
MIT License
23.4k stars 1.49k forks source link

Where contains with reference broken in v2 #3926

Closed dominikzogg closed 10 months ago

dominikzogg commented 10 months ago

Link to reproduction

No response

Describe the Bug

This query worked in v1, but does not in v2: ?depth=0&where[children][contains]=64d5ef3b02daa9eb18051754&page=1&limit=1

children is a one to many relation to the same content type (self referencing)

TypeError: Cannot read properties of undefined (reading 'read')
    at /app/node_modules/payload/src/database/queryValidation/validateSearchParams.ts:140:37
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Promise.all (index 0)
    at async validateSearchParam (/app/node_modules/payload/src/database/queryValidation/validateSearchParams.ts:178:3)
    at async Promise.all (index 0)
    at async validateQueryPaths (/app/node_modules/payload/src/database/queryValidation/validateQueryPaths.ts:85:5)
    at async find (/app/node_modules/payload/src/collections/operations/find.ts:136:7)
    at async findHandler (/app/node_modules/payload/src/collections/requestHandlers/find.ts:30:20)

To Reproduce

Try todo a where contains on a field which is a one2many relation pointing on it self

{
  slug: 'pages',
  fields: [
    {
      name: 'children',
      type: 'relationship',
      relationTo: 'pages',
      hasMany: true,
    }
  ]
}

Payload Version

2.0.13

Adapters and Plugins

mongodb

JarrodMFlesch commented 10 months ago

I think the correct operator to use here would be in. I have been trying to diagnose what changed with contains though too.

JarrodMFlesch commented 10 months ago

Yeah you should use in instead of contains, I am going to close this issue out. Thanks!

dominikzogg commented 10 months ago

@JarrodMFlesch thank you

dominikzogg commented 10 months ago

@JarrodMFlesch i still the the same error

?depth=0&where[children][in]=64d5ef3b02daa9eb18051754&page=1&limit=1

TypeError: Cannot read properties of undefined (reading 'read')
    at /app/node_modules/payload/src/database/queryValidation/validateSearchParams.ts:140:37
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Promise.all (index 0)
    at async validateSearchParam (/app/node_modules/payload/src/database/queryValidation/validateSearchParams.ts:178:3)
    at async Promise.all (index 0)
    at async validateQueryPaths (/app/node_modules/payload/src/database/queryValidation/validateQueryPaths.ts:85:5)
    at async find (/app/node_modules/payload/src/collections/operations/find.ts:137:7)
    at async findHandler (/app/node_modules/payload/src/collections/requestHandlers/find.ts:30:20)
JarrodMFlesch commented 10 months ago

@dominikzogg Ah yes, sorry for closing too soon. The fix is in this PR.

github-actions[bot] commented 2 weeks ago

This issue has been automatically locked. Please open a new issue if this issue persists with any additional detail.