Strapi v4: Is it possible to filter options of a relation field based on a value of a different relation?

System Information
  • Strapi Version: 4.2.0
  • Operating System: MacOS
  • Database: Postgres
  • Node Version: 16.15
  • NPM Version: 6.14.15
  • Yarn Version: 1.22.17

Context: I have a collection type called Product, and this product has two one-to-many relations: Category and Subcategory. Each Product must have a Category. Each Category has an optional one-to-many relation with Subcategory. So, a Product must have a Subcategory only if the Category selected has any Subcategories.

Basically, all I want to do is to filter the options on Subcategory relation’s field based on the Category selected. It will show empty if no Category is selected or if the Category selected does not have a Subcategory.

I’m hoping to maintain the same way it was in the v3 version (layout wise), where I have made an extension of the content-manager plugin to override the SelectWrapper component (and some other components too) to have this business logic. I have searched everywhere and found nothing about this for the strapi v4.

So, how can I achieve this? Is this even possible?

1 Like

Since no one responded, I’ll leave it here the workaround that i have done.

My main issue was to make the relation field have a custom component to insert some business logic. So to do that, I had to modify the SelectWrapper component directly in node modules and save the changes using patch-package.

I have the exact same problem. How did you solve yours?

I have a Parent collection type that has many Children. Each Child lives in a different State {Alaska, California, and so on}. I want to find the Parent that has a child in live in Alaska for example.

like i said above, I used a thrid party lib called patch_package that enables me to make changes on node_modules permanent. I directly changed the behavior of the SelectWrapper component under admin components. This is the component that relation fields uses, so i am able to get multiple information from the context inside that component and pull the options that i want

1 Like

It’s Nov 2023 and I still have this exact same problem. I have collection type called City, each City has many Districts and each district has many Subdistricts.

Have Strapi themselves come up with a solution for this yet?

1 Like

Has anyone found a solution?