Structured Content 2022: Join our conference to explore fresh perspectives on content and digital experiences →

how to limit a reference to just one entry in Studio reference input side versus the default as-many-entries-as-you-fill-in-an-array?

3 replies
Last updated: Sep 18, 2020

Does anyone have a quick pointer/guidance on how to limit a reference to just one entry in Studio

reference
input side versus the default as-many-entries-as-you-fill-in-an-array?

Sep 18, 2020, 2:03 AM

For instance, this is the default:

{
name: ‘related_post’,
title: ‘Post’,
type: ‘array’,
of: [{ type: ‘reference’, to: { type: ‘post’ } }]
}
And I’m perfectly fine with an array of a single reference. I assumed I could add something to the
of
portion, but I didn’t see clear documentation on what’s possible there.
I also didn’t think this was a validation situation either since it’s a limit on adding more. But I could be wrong if that is actually the correct approach.

Is a single reference only done via a unique object?

Guidance or recommendation would be super appreciated.

Sep 18, 2020, 2:07 AM

What’s wrong with just doing this?

{
  title: "Related Post",
  name: "relatedPost",
  type: "reference",
  to: [{ type: "post" }],
}

Sep 18, 2020, 3:55 AM

Yup, that was it

user L
. I didn’t realize I can just direct reference like that. Much appreciated!

Sep 18, 2020, 4:22 AM

Sanity.io: Get the most out of your content

Sanity.io is a platform to build websites and applications. It comes with great APIs that let you treat content like data. Give your team exactly what they need to edit and publish their content with the customizable Sanity Studio. Get real-time collaboration out of the box. Sanity.io comes with a hosted datastore for JSON documents, query languages like GROQ and GraphQL, CDNs, on-demand asset transformations, presentation agnostic rich text, plugins, and much more.

Don't compromise on developer experience. Join thousands of developers and trusted companies and power your content with Sanity.io. Free to get started, pay-as-you-go on all plans.