I'm trying to run a GROQ query for my Sanity.io project that should filter out child documents that contain references based on a grandparents id. Is it possible to do so?
I've come to an understanding that for similar scenarios I could use the parent operator like so:
references(^._id)
But in my case, I need the grandparent id, so I cannot make any use of the parent operator the way I've wrote the query now.
I can also clearly read in the documentation:
Known issue The ^ operator currently only works from subqueries. In all other scopes, it returns the root of the current scope, not the parent scope. It is also not possible to use ^ to refer to grandparent scopes.
But no information about a workaround.
The query currently looks like this. I need pages only that refer to the team id. But right now, using the references(^._id) in the current position (pages), I'm only getting a reference id from the parent (sports) and not from the grandparent (teams) which I need.
*[_type == 'client' && alias == 'ipsum']{
_id, name, teams[]->{
_id, name,
sports[]->{
name,
"pages": *[_type=='page' && references(^.id)]
}
}
}
Thanks in advance, any help at all will be greatly appreciated.