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
25.84k stars 1.65k forks source link

Virtual field breaks searching #8525

Closed wszerad closed 1 month ago

wszerad commented 1 month ago

Link to reproduction

No response

Environment Info

Payload: v3.0.0-beta.110

Describe the Bug

Virtual field is used as search column which causes errors when searching in collection. Additionally, if such a field is used as "useAsTitle", it spoils the relationship search here: UI/Relationship

Reproduction Steps

Create collection like this:

{
  slug: 'students',
  admin: {
    useAsTitle: 'fullName',
  },
  fields: [
    {
      name: 'firstName',
      type: 'text',
    },
    {
      name: 'lastName',
      type: 'text',
    },
    {
      name: 'fullName',
      type: 'text',
      virtual: true,
      hooks: {
        afterRead: [
          (args) => {
            const { firstName, lastName } = args.siblingData
            return `${firstName} ${lastName}`
          }
        ]
      }
    },
  ],
}

Now searching in collection search is broken.

Adapters and Plugins

No response

r1tsuu commented 1 month ago

Virtual fields aren't supposed to search by them. This PR https://github.com/payloadcms/payload/pull/8541 removes a field from the search list if it's virtual and used as useAsTtile. Don't use virtual: true, if you care about filtering by it. And instead of afterRead you can use beforeChange.

github-actions[bot] commented 1 month ago

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

github-actions[bot] commented 1 month ago

🚀 This is included in version v3.0.0-beta.113

github-actions[bot] commented 1 month ago

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