👋 Next.js Conf 2024: Come build, party, run, and connect with us! See all events

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
Corey Ward
. I didn’t realize I can just direct reference like that. Much appreciated!
Sep 18, 2020, 4:22 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?