Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive

Setting up a finite list of predefined categories for documents

3 replies
Last updated: Feb 13, 2023
Hey.
I would like list of finite items (i.e. a category). Let’s say I got 5 items in the list. Every document that uses one item (category) in the list must remove that option for the next documents that will be created. This also implies that it will only be possible to have 5 documents of this particular type “live” at any time, as there will be no more catagories to chooose from.

Could someone help me understand which approach to choose here, or point me to some documentation that covers this?

Thanks in advance for all input.
Feb 12, 2023, 4:45 PM
Check using a filter on the reference field, you can filter out all categories that are referenced already
Feb 12, 2023, 7:36 PM
Cool.
If I may ask:
I want these categories to be predefined. So, I don’’t want the user/admin to be able to create new ones. I tried to make an object with just a list of predefined strings and then use this object as a reference, but that didn’t work.

The categories are just names of colors. So “Blue”, “Red” and so on. Then, another document with the name “team” can use one of these colors, and they must all use a different one.

How would you set this up?
Feb 13, 2023, 12:13 AM
Can probably create it as a semi singleton https://www.sanity.io/guides/singleton-document
Feb 13, 2023, 5:43 AM

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?