Unlock seamless workflows and faster delivery with our latest releases ā€“ get the details

Is there a way to get the key in an array when resolving the references?

6 replies
Last updated: Sep 10, 2020
Is there a way to get the key in an array when resolving the references?
*[_type == "category"] {
events[]-> {_key, _id}
}
I cant find a way to include the
_key
here.
Sep 10, 2020, 9:41 AM
Could you post an example of a category document? Easier to help when seeing the document structure
Sep 10, 2020, 9:59 AM
{
  "events": [
    {
      "_key": "f9d29ec438bf",
      "_ref": "5b94ed5c-064d-4fe8-bafe-e53920984f65",
      "_type": "reference"
    }
  ]
}
Sep 10, 2020, 10:11 AM
events[]{
 _key, 
  @->
}
Perhaps?
Sep 10, 2020, 10:27 AM
Getting close šŸ™‚ I needed to put it in an object.
*[_type == "category"][0] {
events[] {
  _key,
  "something": @-> {...}
}
}
Any ideas how to make attach it to the parent?
Sep 10, 2020, 10:31 AM
  events[]{
    _key,
    ...@->
  }
Sep 10, 2020, 10:32 AM
Nice! Thanks ā¤ļø
Sep 10, 2020, 1:15 PM

Sanityā€“ build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?