Go Behind the Experience to see how Tecovas brings the West to life with Sanity 🀠 July 18th

Customizing Sanity Studio and sorting seminars based on lecturers

27 replies
Last updated: Nov 5, 2021
Hey,I am customizing the Sanity Studio and have hit a roadblock on the S.documentList().filter() when trying to sort seminars based on lecturers. I've been following the guide:
https://www.sanity.io/docs/dynamically-group-list-items-with-a-groq-filter , and many of my prior sortings have worked out fine. The problem is this filter: ('_type == "seminar" && $seminarId == lecturers[].lecturer.__ref') which is similar to categoryId example of the article: ('_type == "post" && $categoryId in categories[]._ref')...
The problem is that in my code with extra nesting it doesnt seem to loop through lecturers[], as I only get a result if I specify an index like so: lecturers[0].lecturers._ref

Is it possible to do something like this with a filter only?

The data I am using this on is as follows:
Nov 4, 2021, 12:29 PM
Instead of
_type == "seminar" && $seminarId == lecturers[].lecturer.__ref
_$seminarId in lecturers[].lecturer.__ref
returns an array, you want to check if
is inside the array not that it is equal to it
Nov 4, 2021, 12:42 PM
When I change it to "in" i get nothing return πŸ€”
What I am trying to do is to return the seminars which have a reference to the lecturer I click in the documentList. This is how it looks for my authors (which follow the categoryId example from the article from the docs)
Nov 4, 2021, 12:56 PM
Shouldn't be the
used instead, not the
Nov 4, 2021, 12:58 PM
oh, this is just a naming oversight on my part, it doesn't change the result from the event. Halfway working code looks like this:
Nov 4, 2021, 1:01 PM
Without the " == " and the "[0] there is no output. This only gives me one of the seminars the lecturer has appeared on however, but I want it to show all πŸ˜…
Nov 4, 2021, 1:06 PM
I will add that this query in Studio Vision is what i think is equivalent (based on testing with my authors) , and it gives the following output:
Nov 4, 2021, 1:18 PM
But adding either "0" or "1" gives me either of the seminars the lecturer is featured:
Nov 4, 2021, 1:20 PM
What's the result of
*[_type == "seminar"].lecturers[].lecturer._ref
in Vision ?
Nov 4, 2021, 1:21 PM
And what
contains?From your first screen I guess it's
fields, right?
Nov 4, 2021, 1:24 PM
That's right.
Nov 4, 2021, 1:25 PM
If it helps, it looks like this:
Nov 4, 2021, 1:26 PM
So based on what you gave to me, this should work.
Nov 4, 2021, 1:30 PM
hmm, "l1" would be the same as my $lecturerId ?
Nov 4, 2021, 1:31 PM
When you used the
keyword, are you sure you wrote it
id in array[]
Nov 4, 2021, 1:31 PM
Nov 4, 2021, 1:32 PM
hmmm, for some reason this still doesn't yield any output for me πŸ€” This is exactly what you told me try first aswell πŸ€”
Nov 4, 2021, 1:37 PM
Really strange. Are you sure you don't have any document in draft?
Nov 4, 2021, 1:39 PM
Is it still returning nothing in Vision?
Nov 4, 2021, 1:40 PM
Everything is in a published state atleast, not sure if there is anything else i could do to be sure πŸ€”
Nov 4, 2021, 1:41 PM
"lecturers" is of type "object" called lecturerContainer, and "lecturer" is a reference to a document type called lecturer. Not sure if this can create a problem..
Nov 4, 2021, 1:47 PM
is an array of object not directly an object right?
Nov 4, 2021, 1:51 PM
yes, sorry. Lecturers is an array that contains lecturerContainer objects
Nov 4, 2021, 1:52 PM
not sure if i need the "to: {type: 'lecturer'}"
Nov 4, 2021, 1:54 PM
I don't think too as it's not an array of references.But I don't think your schema is the cause of the problem.
Maybe try it, who knows...
Nov 4, 2021, 1:56 PM
Hey Eirik! Can you share the url of the query you're running? It's located above the results in Vision.
Nov 4, 2021, 5:32 PM
I've been told that i don't need to pursue it further. I believe what Sixclones did is supposed ot work, so I'll be taking the knowledge with me. But unfortunately I have to stop here πŸ˜…
Nov 5, 2021, 7:11 AM
Thanks for the help πŸ‘
Nov 5, 2021, 7:11 AM

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?