Is it possible to display only selected relationship parameters?

default discord avatar
AkashReddy-playy
2 years ago
1 1

We would like to give editors only specific relationship options of a category, is it currently possible to filter relationship data?

  • discord user avatar
    jmikrut
    Payload Team
    2 years ago

    Hey @AkashReddy-playy — this is a very good question and potentially a great feature request!

    Right now, there is nothing that would allow this but we could extend the Relationship field config to accept a where query constraint that would be used in both the field's validate function as well as its Admin UI component to automatically narrow down relationship field options.

    Outside of building this directly into Payload, you could accomplish this by building your own UI component for use within the React dashboard. We will keep this in mind. It could be a very nice feature to have.

    3 replies
  • default discord avatar
    AkashReddy-playy
    2 years ago

    Thanks, @jmikrut ,
    It could be a valuable feature, much appreciate the response. we will build a react component for now.

  • discord user avatar
    jmikrut
    Payload Team
    2 years ago

    Awesome! Would love to see what you build when you build it.

    You could start by recycling some of the code from our built-in Relationship field here:

    https://github.com/payloadcms/payload/blob/master/src/admin/components/forms/field-types/Relationship/index.tsx

    All you'd need to do to restrict options would be to inject a where query into the fetch that happens in the getResults callback.

    You might also be able to simplify a lot of the code though, say, if your component only supports one relationTo rather than array of options. That is where most of the complexity of this component comes from.

    Looking forward to seeing what you do!

  • default discord avatar
    AkashReddy-playy
    2 years ago

    Thanks @jmikrut , this is a great starting point , we will share any progress.

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

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

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