How to structure a schema in Sanity.io to allow for multiple documents
Looking at your question, I believe you're asking about how to reference multiple documents in a schema field. The most common way to do this in Sanity is using an array of references.
Here's how you structure it in your schema:
{
name: 'relatedArticles',
title: 'Related Articles',
type: 'array',
of: [
{
type: 'reference',
to: [{type: 'article'}]
}
]
}This allows editors to add multiple document references to a single field. If you want to reference multiple different document types in the same array, you can do:
{
name: 'resources',
title: 'Resources',
type: 'array',
of: [
{
type: 'reference',
to: [
{type: 'article'},
{type: 'video'},
{type: 'podcast'}
]
}
]
}As explained in the array fields documentation, array fields create orderable collections where editors can:
- Add as many items as needed
- Reorder them via drag-and-drop
- Remove items
- Each item gets a unique
_keyautomatically
You can also mix different types within the same array if you need more complex structures:
{
name: 'content',
title: 'Content Blocks',
type: 'array',
of: [
{
type: 'reference',
to: [{type: 'article'}]
},
{
type: 'image'
},
{
type: 'object',
name: 'textBlock',
fields: [
{name: 'text', type: 'text'}
]
}
]
}The array approach is much more flexible than single reference fields and is the standard Sanity pattern for "one-to-many" relationships. Editors can add unlimited documents (though you can add validation rules to set min/max limits if needed).
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.