
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeLooking at your issue with filtering seminars based on lecturers in the Structure Builder, the problem you're encountering is related to how GROQ handles nested array references.
The key difference between your filter and the working example from the documentation is the level of nesting. In the documentation example:
'_type == "post" && $categoryId in categories[]._ref'The categories array contains direct references, so categories[]._ref works to extract all reference IDs.
However, in your case with:
'_type == "seminar" && $seminarId == lecturers[].lecturer.__ref'You have an extra level of nesting - lecturers[] is an array of objects, and each object has a lecturer field that contains the reference. The issue is that lecturers[].lecturer.__ref doesn't properly flatten this nested structure in a filter comparison context.
You need to use the in operator instead of ==, combined with proper array dereferencing:
.filter('_type == "seminar" && $lecturerId in lecturers[].lecturer._ref')
.params({lecturerId})Key changes:
in operator instead of == - this checks if the value exists anywhere in the resulting array_ref instead of __ref - the single underscore is the correct property name for references in GROQlecturers[].lecturer._ref will properly extract all reference IDs from the nested structureHere's how your dynamic filtered list should look:
S.documentTypeList('lecturer')
.title('Seminars by Lecturer')
.child((lecturerId) =>
S.documentList()
.apiVersion('2024-06-01')
.title('Seminars')
.filter('_type == "seminar" && $lecturerId in lecturers[].lecturer._ref')
.params({lecturerId}),
)The lecturers[].lecturer._ref projection will create an array of all lecturer reference IDs from your nested structure, and the in operator will check if your $lecturerId parameter exists in that array.
This should work with your nested structure without needing to specify an index like [0]. The array projection syntax lecturers[].lecturer._ref automatically handles the iteration through all items in the lecturers array.
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store