Relationship add new with default

default discord avatar
7 months ago

When creating a new item through a relationship filed, and the relationship only can contain items with a category.

      name: "wheels",
      type: "relationship",
      filterOptions: (args) => {

        return { category: { equals: "wheels" } };
      relationTo: ["spare-parts"],

Can I set the default value for the new relationship item "wheels.category" in the remote collection to "wheels" when added through a relationship?

My solution was to disable edit and create for the relationship field.

  • default discord avatar
    6 months ago

    Hi @martin.rahbek I tried your code.

    But how did you set the default value?

  • default discord avatar
    6 months ago

    defaultValue: () => {

            // query the default and return it here

            return {

              value: "53673f577e92b8ea049d3ca5",

              relationTo: "spare-parts",



Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!


Connect with the Payload Community on Discord



Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.