Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive

Getting an Array of References without an Object Wrapper

1 replies
Last updated: Jan 6, 2023
Can I get an array of references without an object wrapper? When i write:
*[_id == $id ].featuredPosts[]->{The elements I want}
it returns null, and if I instead wrap featuredPosts with curly brackets it returns what I want, but with the additional layer
{featuredPosts: [Result I want to be returned]}
.
Jan 6, 2023, 2:52 PM
Figured it out. I could just add parentheses like this:
*[_id == $id ].(featuredPosts[]->{The elements I want})[0]
Jan 6, 2023, 3:05 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?