I’m having some trouble figuring out how to query inside references still.

9 replies
Last updated: Jan 14, 2021
I’m having some trouble figuring out how to query inside references still.
Jan 14, 2021, 3:08 AM
If I query this:
*[_type == "darkroomphoto"] {
  aperture,
  photo
}
and I get this:
Jan 14, 2021, 3:08 AM
Weird, I just came here to ask how to do the same from within a filter:
{
      name: "extras",
      title: "Extras",
      type: "array",
      of: [
        {
          type: "reference",
          to: {
            type: "product",
          },
          options: {
            filter: "menu._ref == $menu._id",
            filterParams: {
              menu: "Extras",
            },
          },
        },
      ],
    },

Jan 14, 2021, 3:09 AM
If I run this:
*[_type == "darkroomphoto"] {
  aperture,
  "photo": {
  	asset->
  }
}
It comes up empty like this:
Jan 14, 2021, 3:10 AM
if you use "photo" than you made a custom property, try just photo without quote.
Jan 14, 2021, 3:25 AM
yikes, I’m 2 for 2 on obvious questions now 😅. Thanks
user G
!
Jan 14, 2021, 3:26 AM
Try replacing
"photo": { asset-> }
with
"photo": photo.asset->
Jan 14, 2021, 3:27 AM
Or that works too. 😀
Jan 14, 2021, 3:27 AM
Is it possible to query for a field within a reference in
options: {filter: {}}
? 👀
Jan 14, 2021, 3:28 AM
both worked, but
"photo": photo.asset->
was a bit neater so both suggestions were really helpful
Jan 14, 2021, 3:28 AM

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