Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding defaultSort to collection config breaks relationship field search. #197

Closed
iamlinkus opened this issue May 9, 2024 · 3 comments
Closed
Assignees

Comments

@iamlinkus
Copy link

How to reproduce:

  1. Pull this repo.
  2. Modify the pages collection like so:
    {
      slug: 'pages',
      admin: {
        useAsTitle: 'title',
      },
      defaultSort: 'createdAt',
      fields: [
        {
          name: 'relationship',
          type: 'relationship',
          relationTo: 'pages',
        },
        {
          name: 'title',
          type: 'text',
        },
      ],
    },
  1. npm run dev, login to the admin, create a few pages.
  2. Open one page, click on the relationship field and start typing.

The field errors out. And the errors are different. Sometimes it's something like

ERROR: TypeError: Cannot destructure property 'operator' of '(0 , _sanitizeQueryValue_js__WEBPACK_IMPORTED_MODULE_3__.sanitizeQueryValue)(...)' as it is undefined.
    at buildSearchParam (webpack-internal:///(rsc)/./node_modules/.pnpm/@payloadcms+db-mongodb@3.0.0-beta.22_payload@3.0.0-beta.22/node_modules/@payloadcms/db-mongodb/dist/queries/buildSearchParams.js:58:27)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

If I add a date field and it's set in all pages and I set it to be the defaultSort: '-date', it's:

ERROR: QueryError: The following path cannot be queried: -date
@andershermansen
Copy link

Note that this is an existing bug in v2. Ref payloadcms/payload#4815
I suggested a fix for v2 in payloadcms/payload#5964 but have not yet heard from the maintainers.

@andershermansen
Copy link

Fix for v2 is merged.
Fix for v3 is ready for review payloadcms/payload#6440

@denolfe
Copy link
Member

denolfe commented May 21, 2024

Merged for v2 and v3.

@denolfe denolfe closed this as completed May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants