Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Have relationship field show a different field from the related entity rather than ID

default discord avatar
zenwhiskers04 weeks ago
1

import { CollectionConfig } from "payload";



export const Artists: CollectionConfig = {


slug: "artists",


fields: [


{


name: "name",


type: "text",


required: true,


},


{


name: "tracks",


type: "join",


collection: "tracks",


on: "artist",


},


],


};



import {


HTMLConverterFeature,


lexicalEditor,


lexicalHTML,


} from "@payloadcms/richtext-lexical";


import { CollectionConfig } from "payload";



export const Tracks: CollectionConfig = {


slug: "tracks",


admin: {


useAsTitle: "title",


},


fields: [


{


name: "artist",


type: "relationship",


relationTo: "artists"


},


],


};



When I go to assign an Artist to a Track from the Track page, the Track page shows the id of the artist (currently "1" or "2"). I'd like it to instead say the artist.name. I did not see this in the docs, so sorry if I missed it, still learning!



I figured it out. I need to use { admin: useAsTitle: name } } on the Artists collection config

  • default discord avatar
    webdevkaleemlast month

    thank you for sharing the solution

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.