I have three custom types : zones, brands and products. The product type has a relationship to a zone, and to a brand.
How can I retrieve a list of all zones where at least one product is related to the zone and related to brand X ? Also, retrieve all brands for which at least one product is related to this brand and related to zone X ?
I can use graphQL or the SDK or anything else. We are using PHP
Thank you for your answer, unfortunately it is not possible to add relationships to brands because there are like 10k products and it seems that a relationship field can only link to one document. There are of course many products for one pair of zone/brand.
Could you show me an example of GraphQL query where I can intersect zones or brands with the products for a given brand / zone ?
Forget about the "product" because it is a bad example. Let's use "office" instead.
What we want is "List all the zones that have at least one office for brand X in the zone".
For instance, with two zones, Germany and France, and two brands, Microsoft and Apple, I would like to query the zones where there is at least one Microsoft office.
So if I have
Office 1, Microsoft, France
Office 2, Microsoft, Germany
Office 3, Apple, France
I want a query that takes Microsoft as an argument and would return France and Germany zone documents, because both have at least one document of prismic-type Office with a relationship to the Microsoft entity.
If the query argument is Apple, it would only return the France document.
What we do now is something like : query all offices related to the zone, map over the offices and if has a relationship to the desired brand, keep the related zone in an array (if not already in). Then we have all our zones for the brand.
But I would like to know if it is possible to to that directly in the query.
Sorry, this was a made up example, I don't remember the entities very well since I have not worked on that project for a while.
Thanks for the extra detail this really clears things up.
I think the idea stays the same you would have to use the where argument to query by Offices with a relationship linked to brand Microsoft and then filter on your front end of your project from what the content relationship zone contains.
Unfortunately though there would be no way to Have Microsoft as the query argument and return the zone.