đŸ‘‹ Next.js Conf 2024: Come build, party, run, and connect with us! See all events

Proper way to enforce a single document type in Sanity schema, with deprecation warning for deskTool.

5 replies
Last updated: Mar 26, 2024
Hey Sanity Team. I am new to using sanity and am wanting to implement a single document type in my schema for my authors. I was looking at the following guide https://www.sanity.io/guides/singleton-document but when I tried to implement it, I got a deprecation warning for deskTool in sanity/desk. What is the proper way to enforce that the author can only implement a single document for one of my schema types? (ex. wanting to make the document for text on a webpage)
Mar 26, 2024, 2:53 PM
You are on the right track however like you noticed there is a deprecation warning, switch sanity/desk for sanity/structure.
Or you could use the following plugin -
https://www.sanity.io/plugins/singleton-tools , just used on one of my projects and it's amazing
Mar 26, 2024, 3:05 PM
O snap, I will take a look. Thanks!
Mar 26, 2024, 3:08 PM
Oh hey! I made that plugin. Glad you like it!
Mar 26, 2024, 3:54 PM
Works like charm! Could be just because I am new, but if you impose the singleton option on a schema, how do you make it so that there is a new single document by default? Do I have to create the doc before I set the option?
Mar 26, 2024, 4:03 PM
If you use the
singletonDocumentListItem
in your structure it’ll create a singleton with whatever
id
you pass in the first time you open it.
Mar 26, 2024, 4:05 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?