Is there an easy way to get the reference data in a deeply nested component? I have a list of different components, some of them have arrays of references which I’d liketo...

3 replies
Last updated: Jan 6, 2021
Is there an easy way to get the reference data in a deeply nested component? I have a list of different components, some of them have arrays of references which I’d like to expose. I’ve managed to get one of the components to expose the references, but it overrides the entire array with empty objects for all the other components.
body[]{ links[]-> }
What I need is a
*
to expose the original content, but override certain fields.
Jan 6, 2021, 11:07 AM
not 100% I understand you, and I'm a GROQ newbie myself but have you tried this

body[] {
  ...,
  links[]->
}

Jan 6, 2021, 11:11 AM
Pretty sure youre looking for something like this:

body[] {
  links[]-> {
    "aThing": title,
    ...
  }
}
The triple dot will display all properties of an object within the
links
array,
"aThing": title
assigns the
title
property to
aThing
Jan 6, 2021, 11:11 AM
Thanks! Exactly what I was looking for!
Jan 6, 2021, 11:11 AM

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.

Was this answer helpful?