See Sanity in action 👀 Join us for a live product demo + Q&A →

Querying and opening up references to carousels in Sanity.io

6 replies
Last updated: Mar 2, 2023
Any idea how i can query and open up the reference to carousels?

 title: 'Sidemoduler',
      name: 'modules',
      type: 'array',
      description: 'test',
      of: [
        { type: 'icons'},
        { type: 'reference',
          title: 'Carousel',
          name: 'carousel',
            to: [{ type: 'carousels' }]
          }
      ],
all i get with this query :

 *[_type == 'page']{
 modules[]{
   _type=="carousel" => {...}
    }
    }
is :

_key:3931b8414f42
_ref:ad5572b5-104d-4ffd-a6f4-a5058f2392f4
_type:carousel
Mar 2, 2023, 8:48 PM
Hi
user F
. Could you please try changing that
_type
line in your query to this?

_type=="reference" => @->
Mar 2, 2023, 8:52 PM
you are an angel
Mar 2, 2023, 8:53 PM
thanks alot! So what does the @-> actually do? open all refs?
Mar 2, 2023, 8:54 PM
You can think of
@
a bit like
this
, so it’s saying “for anything that’s a reference type, dereference it.”
Mar 2, 2023, 8:54 PM
nice, thanks!
Mar 2, 2023, 8:57 PM
Throughout the docs you’ll tend to see the dereference operator (
->
) following some property, such as here , but in this case we can’t really do that because what “this” is, changes.
@
is the thing that’s currently in scope, and when it’s of the “reference” type, it gets applied. You might write the same thing as:

select(
  _type == 'reference' => @->,
  @
)
Mar 2, 2023, 8:58 PM

Sanity.io – build remarkable experiences at scale

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

Categorized in