Like what we’re doing? Star us on GitHub!

Is it possible to display only selected relationship parameters?

AkashReddy-playy
last year
1 1

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

  • jmikrut
    Payload Team
    last year

    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
  • AkashReddy-playy
    last year

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

  • jmikrut
    Payload Team
    last year

    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!

  • AkashReddy-playy
    last year

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

Open the post
Continue the discussion in GitHub
Can't find what you're looking for?
Get help straight from the Payload team with an Enterprise License.Learn More