Schema Specification for a Document - Is There a Way to Specify That Field To Be Unique?
unique()function to the validation. This requires all values within the array to be unique by doing a deep comparison.
{
title: 'Category Set',
name: 'categorySet',
type: 'array',
of: [{type: 'string'}],
validation: Rule => Rule.unique()
}Given this:
type: 'document',
title: 'Language texts',
name: 'i18n',
fields: [
{
name: 'key',
title: 'Identifier',
type: 'string',
},
{
name: 'value',
title: 'Translations',
type: 'localeString',
},
]keyfield to be unique.
keyfield. Thank you very much! 🙂
uniquerule is not valid on document descriptors. I wish it was.
That leaves me with trying to create a custom rule which queries for document keys on input. Anybody have a clue as to how I can query existing objects inside a custom rule?
This should be part of the documentation.
Was this answer helpful?
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.