Relationship add new with default

default discord avatar
martin.rahbeklast year

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
    dnl.krmr12 months ago

    Hi @martin.rahbek I tried your code.

    But how did you set the default value?

  • default discord avatar
    martin.rahbek12 months ago

    defaultValue: () => {

            // query the default and return it here

            return {

              value: "53673f577e92b8ea049d3ca5",

              relationTo: "spare-parts",



Star on GitHub


Chat on Discord



Can't find what you're looking for?

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