Reputation: 107
We have certain type of fields that point to a reference that we want to resolve. Is there a way to search for these fields, however deep down the tree they are, and apply the "->" on it? We have prefixed these field with "msg_".
An example structure might look like this, but could also be buried deeper into another "children" array:
"children":[
0:{
"_key":"e0baca937bf2"
"_type":"hero"
"backgroundImage":{...}
"msg_subtitle":{
"_ref":"2459a16f-8d54-4f7a-8a57-31ad6a100d44"
"_type":"reference"
}
"msg_title":{
"_ref":"91cb61db-029b-4117-8872-154c190f4195"
"_type":"reference"
}
}]
So we want all the fields starting with "msg_" 's hard reference.
Upvotes: 1
Views: 1942
Reputation: 749
You can't recursively traverse references in GROQ yet.
Were you thinking about something like this? I'm not exactly sure what you mean by search
.
That would indeed be handy to have a possibility like that. That said, in many of these cases we have been asked about this before, we have uncovered that it's fine to use the ->
explicitly, and at the same time found content modeling problems.
The answer to this question is no, but feel free to reach out in the Community Slack: https://slack.sanity.io/. It may be that we can help you out some more there, and it's easier to have discussions there.
Upvotes: 3