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

Relationship fields are not searchable in the List View #10649

Open
mfilteau opened this issue Jan 17, 2025 · 2 comments
Open

Relationship fields are not searchable in the List View #10649

mfilteau opened this issue Jan 17, 2025 · 2 comments
Labels
enhancement New feature or request status: needs-triage Possible bug which hasn't been reproduced yet

Comments

@mfilteau
Copy link

Describe the Bug

If we have a collection where a relationship field is identified as searchable:

export const Orders: CollectionConfig = {
  slug: 'orders',
  admin: {
    useAsTitle: 'orderNumber',
    listSearchableFields: ['customer'], // <--- field is relationship type
  },
  fields: [
    {
      name: 'orderNumber',
      type: 'text',
      required: true,
    },
    {
      name: 'date',
      type: 'date',
    },
    {
      name: 'product',
      type: 'relationship',
      relationTo: 'products',
    },
    {
      name: 'customer',
      type: 'relationship',
      relationTo: 'customers',
    },
  ],
}

The field appears to the user as searchable (in the list search placeholder) but nothing happens.

2025-01-17_15-46-03.mp4

Link to the code that reproduces this issue

https://github.com/mfilteau/payload-bugs

Reproduction Steps

  1. Seed the database

http://localhost:3000/api/seed

  1. Go to the Orders list view in admin panel

  2. See that the list should be searchable by Customer

  3. Try entering a customer name in the search box.

Nothing happens.

Which area(s) are affected? (Select all that apply)

area: ui

Environment Info

Binaries:
  Node: 20.10.0
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  payload: 3.17.1
  next: 15.1.0
  @payloadcms/db-mongodb: 3.17.1
  @payloadcms/email-nodemailer: 3.17.1
  @payloadcms/graphql: 3.17.1
  @payloadcms/next/utilities: 3.17.1
  @payloadcms/payload-cloud: 3.17.1
  @payloadcms/richtext-lexical: 3.17.1
  @payloadcms/translations: 3.17.1
  @payloadcms/ui/shared: 3.17.1
  react: 19.0.0
  react-dom: 19.0.0
Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Pro
  Available memory (MB): 65457
  Available CPU cores: 16
@mfilteau mfilteau added status: needs-triage Possible bug which hasn't been reproduced yet validate-reproduction labels Jan 17, 2025
@DanRibbens
Copy link
Contributor

DanRibbens commented Jan 21, 2025

This isn't documented properly, but what you can do is include in your listSearchableFields the relationship properties you want to search. For example, instead of ['customer'] use ['customer.email', 'customer.name'] // etc.

This way you can search any fields of a relationship and get results back.

What we intend to do is add the searchable fields of the relationship automatically. That would either work by id, the useAsTitle field or the listSearchableFields of the related collection. This gets a little more complicated with polymorphic relationships, but that is something we can worry about later.

@mfilteau
Copy link
Author

Hi Dan,

I did change the listSearchableFields to 'customer.name' before but I got misled by the fact that the UI was showing a wrong placeholder:

Image

I just tried it again and the search works. It's just a placeholder bug now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request status: needs-triage Possible bug which hasn't been reproduced yet
Projects
None yet
Development

No branches or pull requests

2 participants