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.

Displaying RelationTo Data by Name

default discord avatar
taun21602 years ago
2

How do I display the Category Names in the dropdown, as opposed to their ID string? Currently they're labeled as Untitled, though they have label names.



import { CollectionConfig } from 'payload/types';

const Items: CollectionConfig = {
  slug: 'items',
  admin: {
    useAsTitle: 'name',
  },
  access: {
    read: () => true,
  },
  fields: [
    {
      name: 'name',
      type: 'text',
    },
    {
      name: 'description',
      type: 'text',
    },
    {
      name: 'category',
      type: "relationship",
      relationTo: "portfolioCategories",
    },
  ],
  timestamps: false,
}

export default Items;




import { CollectionConfig } from 'payload/types';

const PortfolioCategories: CollectionConfig = {
  slug: 'portfolioCategories',
  admin: {
    useAsTitle: 'title',
  },
  access: {
    read: () => true,
  },
  fields: [
    {
      name: 'name',
      label: 'Portfolio Categories',
      type: 'text',
    },
  ],
  timestamps: false,
}

export default PortfolioCategories;
  • default discord avatar
    kvist__2 years ago

    useAsTitle needs to be a field on the collection - use "name" instead of "title" 🙂

  • default discord avatar
    taun21602 years ago

    That worked, thanks.

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.