Querying all children of document type where parent is linked

Hi, i am trying to write the smartest query possible using Predicates. I read this article on querying content relationships: https://prismic.io/docs/php/query-the-api/query-by-content-relationship

I have s custom content type called applications. Every application (grandchild) belongs to an application cluster (child) which further belongs to an industry (parent, also custom content types). Application areas (children) are referenced as a linked document (content relationship) in the application (grandchild).

I no want to query all applications linked to a certain industry. My idea was to do this as follows:

  • as applications are grandchildren of an industry i first query all application areas

  • i use the array of application areas to retrieve all referenced applications

    Predicates::at(‘document.type’, ‘application’),
    Predicates::at(‘my.application.application_area.category_link’, [‘area-id-1’, ‘area-id-2’, '…])

Using multiple values for the category_link query does not seem to work. Is there a smarter way to retrieve the data than just doing a single query for every linked category?

Hi @m.feit, I think that there are a couple of things that need to be changed with your query.

  1. When querying by an array of options, you need to use the any predicate, not the at predicate.

  2. When querying by a Content Relationship field, you need to specify the document ID, not it’s UID.

Give that a try and see if you manage to get it working!

Thanks, that helped!

1 Like