We would like to give editors only specific relationship options of a category, is it currently possible to filter relationship data?
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.
Thanks, @jmikrut ,
It could be a valuable feature, much appreciate the response. we will build a react component for now.
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:
All you'd need to do to restrict options would be to inject a
where query into the
fetch that happens in the
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!
Thanks @jmikrut , this is a great starting point , we will share any progress.