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.

Limit number of relationTo in a block

default discord avatar
ux_bob3 years ago
3

I have a block that is pulling in a stats collection, but I'd like to set the min/max of that field. Am I thinking about this in the wrong way?


const Statistics: Block = {
  slug: 'statistic',
  labels: {
    singular: 'Statistic',
    plural: 'Statistics',
  },
  fields: [
    {
      name: 'stat',
      label: 'Statistic(s)',
      type: 'relationship',
      hasMany: true,
      relationTo: 'stat',
    },
  ],
};


How do I limit the number of stats a person is allowed to use?

  • discord user avatar
    jacobsfletch
    3 years ago

    Hi

    @540666559170084875

    this is not currently supported out of the box but would make a

    great

    new feature

  • default discord avatar
    ux_bob3 years ago

    well, i guess this is one way to do it 🙂

    const StatisticsBlock: Block = {
      slug: 'statisticBlock',
      labels: {
        singular: 'Statistic Block',
        plural: 'Statistic Blocks',
      },
      fields: [
        {
          name: 'statArray',
          label: 'Statistic(s)',
          type: 'array',
          minRows: 1,
          maxRows: 3,
          fields: [
            {
              name: 'stat',
              type: 'relationship',
              relationTo: 'statistic',
            },
          ],
        },
      ],
    };
  • discord user avatar
    jacobsfletch
    3 years ago

    Good thinking! That’s a nice little workaround for now.

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.