How to access parent field from reference context using @ in GROQ?
Based on your question, it sounds like you're looking for the parent operator (^) rather than the @ operator. This is a common point of confusion in GROQ!
The @ operator represents the current scope - whatever object you're currently working with. It doesn't let you access fields from outside the current context. The ^ operator is what you need to access parent scope values.
Here's how to read the isSignLanguage field from outside your rightsList reference context:
{
...,
"rightsList": rightsList[]-> {
...,
"parentIsSignLanguage": ^.^.isSignLanguage
}
}Let me break down what's happening:
- First
^- moves up from the dereferenced document back to the array element context - Second
^- moves up from the array element to your parent document whereisSignLanguagelives
The number of ^ operators you need depends on how many scope levels deep you are. In your case with rightsList[]->, you're two levels deep (array projection and reference dereferencing), so you need ^.^.
Important note: There was a bug with the parent operator that was fixed in API version 2021-03-25. If you're using an older API version, the parent operator might not work correctly. Make sure you're using a recent API version.
The confusion between @ and ^ is understandable since both use special symbols, but remember:
@= current scope (what you're looking at right now)^= parent scope (go up one level)
You can chain multiple ^ operators like ^.^.^.fieldName to traverse multiple levels up in your query hierarchy.
Show original thread4 replies
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.