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

GROQ - Subquery with Dereferencing Issue

1 replies
Last updated: Jun 21, 2022
is there a known bug with regard to a query like this?

*[
  _type == 'celeb' &&
  count(*[
    _type == 'fact' &&
    '9171bdb4-1a9b-4cb0-a967-211790a44073' in tags[].tag->_id &&
    celeb._ref == ^._id
  ]) > 0
]
I'm trying to get
celebs
that have a
fact
, where one of the
facts
has a
tag
of a certain ID.
My "bug" is in this line
'9171bdb4-1a9b-4cb0-a967-211790a44073' in tags[].tag->_id
. If I replace that line with a simple condition that doesn't have further de-referencing, it works as expected. The query inside
count
also works as expected when it is a stand-alone query. It just doesn't work (i.e. returns an empty array) when it is used a subquery.
I'm wondering if I'm experiencing the same issue described
here .
Jun 21, 2022, 6:38 PM
I just found out that if I simply change
tag->_id
to
tag._ref
the query will work

*[
  _type == 'celeb' &&
  count(*[
    _type == 'fact' &&
    '9171bdb4-1a9b-4cb0-a967-211790a44073' in tags[].tag._ref &&
    celeb._ref == ^._id
  ]) > 0
]
Jun 21, 2022, 9:40 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?