How to do reference access only if the object in an array is a reference. #4155
Unanswered
choutkamartin
asked this question in
Sanity Studio Support
Replies: 2 comments
-
I was dealing with the similar thing and found this: https://www.sanity.io/schemas/projection-of-a-reference-item-in-a-deeplinked-optional-array-69e62a8c :) Maybe this is what you are looking for? |
Beta Was this translation helpful? Give feedback.
0 replies
-
For everyone who is still wondering how to do this:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi!
I'm kinda new to GROQ. I would like to ask how can I query the following correctly:
When I query the schema this way:
I get this:
The array can contain a normal object or an reference to page. However, if it's not a reference, then of course, the query returns null on the object that is not a reference. Can I somehow do some kind of if statement inside GROQ? (If
type == reference
, then do reference access otherwise do nothing and only return the object.Thanks 🙂
Beta Was this translation helpful? Give feedback.
All reactions