Document References - No Results for Document Type, Changed from Object
7 replies
Last updated: Mar 15, 2021
AI Update
I can see the issue in your schema! Looking at the pastebin, on lines 11-22, you have a duplicate type definition that's causing the problem:
{
type: "string", // ← Line 12: This is wrong!
title: "Related success criterion",
name: "accessibilityRelatedSuccessCriterion",
type: "array", // ← Line 14: This gets overridden by line 12
of: [
{
type: "reference",
to: [{ type: "successCriterion" }],
},
],
},The fix: Remove the type: "string" on line 12. It should be:
{
title: "Related success criterion",
name: "accessibilityRelatedSuccessCriterion",
type: "array",
of: [
{
type: "reference",
to: [{ type: "successCriterion" }],
},
],
},Why you're getting "No results":
- The duplicate type definition was making the field a string instead of an array of references, breaking the reference functionality
- Schema needs to reload - After changing from object to document type, you need to restart your Studio
- Documents must be published - References typically only show published documents by default, not drafts
Steps to fix:
- Correct the schema by removing the duplicate
type: "string"line - Restart your Sanity Studio completely (stop and restart
sanity dev) - Make sure you've published (not just saved as drafts) some
successCriteriondocuments - Try the reference field again - the search should now work!
You were absolutely right that references only work with document types (not objects), so that change was necessary. Once you fix the duplicate type and restart, everything should work as expected! 🙂
Sanity – Build the way you think, not the way your CMS thinks
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.