Customizing Sanity Studio and sorting seminars based on lecturers
27 replies
Last updated: Nov 5, 2021
E
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:
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
S
Instead of
_type == "seminar" && $seminarId == lecturers[].lecturer.__reftry
_$seminarId in lecturers[].lecturer.__ref.Because
_lecturers[].lecturer.__refreturns an array, you want to check if
$seminarIdis inside the array not that it is equal to it
Nov 4, 2021, 12:42 PM
E
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)
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
S
Shouldn't be the
$lectureridused instead, not the
$seminarId?
Nov 4, 2021, 12:58 PM
E
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
E
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
E
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
E
But adding either "0" or "1" gives me either of the seminars the lecturer is featured:
Nov 4, 2021, 1:20 PM
S
What's the result of
in Vision ?
*[_type == "seminar"].lecturers[].lecturer._ref
Nov 4, 2021, 1:21 PM
S
And what
lecturers[].lecturercontains?From your first screen I guess it's
_typeand
_reffields, right?
Nov 4, 2021, 1:24 PM
E
That's right.
Nov 4, 2021, 1:25 PM
E
If it helps, it looks like this:
Nov 4, 2021, 1:26 PM
S
So based on what you gave to me, this should work.
Nov 4, 2021, 1:30 PM
E
hmm, "l1" would be the same as my $lecturerId ?
Nov 4, 2021, 1:31 PM
S
When you used the
inkeyword, are you sure you wrote it
id in array[]?
Nov 4, 2021, 1:31 PM
S
Yep
"l1"is
$lecturerId
Nov 4, 2021, 1:32 PM
E
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
S
Really strange. Are you sure you don't have any document in draft?
Nov 4, 2021, 1:39 PM
S
Is it still returning nothing in Vision?
Nov 4, 2021, 1:40 PM
E
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
E
"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
S
lecturersis an array of object not directly an object right?
Nov 4, 2021, 1:51 PM
E
yes, sorry. Lecturers is an array that contains lecturerContainer objects
Nov 4, 2021, 1:52 PM
E
not sure if i need the "to: {type: 'lecturer'}"
Nov 4, 2021, 1:54 PM
S
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...
Maybe try it, who knows...
Nov 4, 2021, 1:56 PM
R
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
E
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
E
Thanks for the help π
Nov 5, 2021, 7:11 AM
Sanityβ build remarkable experiences at scale
The Sanity Composable Content Cloud is the headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.