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.66k stars 1.52k forks source link

Related field text in dialogues #4911

Open DanRibbens opened 8 months ago

DanRibbens commented 8 months ago

Discussed in https://github.com/payloadcms/payload/discussions/4908

Originally posted by **mat-twg** January 24, 2024 Hi all, i have collection `Documents` with related field `Type` ![image](https://github.com/payloadcms/payload/assets/64251479/75265864-86d6-45ae-a9cc-1d0e03cccae5) ![image](https://github.com/payloadcms/payload/assets/64251479/4b038828-94fa-47f5-a136-35ab14128873) Also i have array field to select uploaded file from `Documents` collection ![image](https://github.com/payloadcms/payload/assets/64251479/626a19d1-ba30-4cd5-8fb4-67ed8d9a0473) problem: when i try pick up document i have incorrect type column value, how to fix it? ![image](https://github.com/payloadcms/payload/assets/64251479/43403e41-ceb7-4cbf-8e45-c6b7199feaa8) -- code snippets `Some collection with array field` ```js { label: 'Documents', fields: [ { name: 'documents', type: 'array', fields: [ { name: 'file', type: 'upload', relationTo: 'documents', required: true, }, ], }, ], } ``` `Documents collection` ```js export const Documents: CollectionConfig = { slug: 'documents', admin: { useAsTitle: 'name', listSearchableFields: ['filename', 'name', 'type.name'], }, upload: { staticDir: path.resolve(__dirname, '../../../../documents'), mimeTypes: ['application/pdf'], }, access: { read: () => true, }, fields: [ { name: 'type', type: 'relationship', relationTo: 'documents-types', required: true, }, { name: 'name', type: 'text', required: true, }, ], } ``` `Documents Types Collection` ```js export const DocumentsTypes: CollectionConfig = { slug: 'documents-types', admin: { useAsTitle: 'name', }, access: { read: () => true, }, fields: [ { name: 'name', type: 'text', required: true, }, ], } ``` -- output example (depth=2) ```js { "documents": [ { "file": { "id": "65b0f6f088e3bb1030dfc4ee", "type": { "id": "65a63e8cf29dbfb651f202a1", "name": "type2", "createdAt": "2024-01-16T08:30:04.683Z", "updatedAt": "2024-01-24T11:38:23.212Z" }, "name": "Passport", "filename": "bc9eb3f3e4394370ab20c26fc0a33627.pdf", "mimeType": "application/pdf", "filesize": 1051811, "createdAt": "2024-01-24T11:39:28.945Z", "updatedAt": "2024-01-24T11:39:28.945Z", "url": "http://localhost:3000/documents/bc9eb3f3e4394370ab20c26fc0a33627.pdf" }, "id": "65b0f9d3dabf001336b857dd" } ] } ```
DanRibbens commented 8 months ago

@mat-twg

It looks like a bug so I've opened an issue from your discussion.

The relation for type should be populating in order to show the title that you have for the useAsTitle which in your case is the name field.