
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeBased on what you're describing, there are a couple of approaches to solve this problem, though auto-populating parent references isn't the typical pattern in Sanity.
Instead of auto-populating references in the parent document, I'd recommend structuring your schema so that children reference their parent. Then you can query all children for a given parent using GROQ. This is the most common pattern because:
Here's how it works:
Child schema:
{
name: 'child',
type: 'document',
fields: [
{
name: 'parent',
type: 'reference',
to: [{type: 'parent'}]
},
{
name: 'orderRank',
type: 'string',
hidden: true
}
// other fields
]
}Query to get sorted children:
*[_type == "parent" && _id == $parentId][0] {
...,
"children": *[_type == "child" && parent._ref == ^._id] | order(orderRank)
}For manual sorting, use the Orderable Document List plugin which provides drag-and-drop ordering functionality in Studio using the orderRank field.
If you really need the parent to contain an array of child references, you can use Sanity Functions to automatically update the parent when children are created. Functions are Sanity's modern, serverless compute solution that runs directly on Sanity's infrastructure - no external hosting needed.
You'd set up a Function that:
orderRank for sortingHowever, this approach has downsides:
A third option is to manually manage references in the parent, but make it less tedious:
{
name: 'parent',
type: 'document',
fields: [
{
name: 'children',
type: 'array',
of: [{
type: 'reference',
to: [{type: 'child'}]
}]
}
]
}The array itself is drag-and-drop sortable in Studio, so users can reorder as needed. While they need to manually add children, this gives them complete control over which children appear and in what order.
For your use case, I'd strongly recommend the reverse reference + Orderable Document List approach - it's cleaner, more maintainable, and gives users the sorting control they need without manual reference management.
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