Filter on content relationship nested field

Hello,

I'm using "@prismicio/client": "^7.1.0" and I would like to know if it's possible to filter on content relationship nested field.

Example:
I have two custom types: article and category.

  • article.category is a content relationship field
  • category.mysubfield = "a" | "b" | "c"

I would like to use client.getByType with a filters options like this:

filters: [filter.any("my.article.category.mysubfield", ["a", "b"])]

I've also tried to preload the categories and use an array of IDs, with in or any operator, but didn't work either:

filters: [filter.in("my.article.category",  categories.map(({ id }) => id))]

ps: I'm well aware of Content Relationship - Documentation - Prismic and @prismicio/client Technical Reference - Documentation - Prismic

Thank you for your time,
Raphael

Filtering on nested fields within a Content Relationship is not supported directly but you can still query first level content from linked documents using REST

my.[custom-type].[relationship-field]

Hello,

Thanks for your response.
Looks like there is no proper solution but I've managed to do with a combinaison of loading the sub collection and the any operator

filter.any(
        "my.article.category",
        categories.map(({ id }) => id),
      ),
1 Like