Understanding how to create inline documents with reference fields in Slack thread

4 replies
Last updated: Jun 19, 2023
Still getting to grips with everything, presently trying to understand creating documents inline.I've a got reference field for a 'teamMember', and created and published an entry inline, but the new 'teamMember' doesn't show up under my 'Team Members' documents?
AI Update

When you create a document inline through a reference field in Sanity Studio, you might notice it doesn't immediately appear in your main document list. This is actually expected behavior, and here's why:

Understanding Inline Document Creation

When you create a document inline from a reference field, Sanity creates a draft of that document. By default, the main document list views in Studio only show published documents. Your newly created team member exists as a draft (with an ID prefixed by drafts.) but hasn't been published yet.

How to See Your New Document

You have a few options:

  1. Publish the parent document: When you publish the document that contains the reference field, you'll be prompted to also publish the referenced document (your new team member). This is Sanity's way of maintaining referential integrity.

  2. Navigate directly to Team Members: Go to your Team Members document type in Studio. You should see the draft there with a draft indicator. You can then publish it independently.

  3. Check your draft documents: Some Studio configurations show drafts alongside published documents in list views. Look for a draft indicator or toggle.

Why This Happens

According to the reference field documentation, when you create and publish new documents inline from a reference field, the referring document will be blocked from publishing until the referenced document has been published. This ensures you don't end up with published documents referencing unpublished content.

The exception to this rule is if you're using a weak reference (configured with weak: true), which allows references to documents that may not exist or haven't been published yet.

Quick Fix

Simply publish your main document that contains the team member reference, and you should be prompted to publish the team member as well. After that, it will appear in your Team Members list!

Would you mind showing a snippet from your schema where you’re creating the reference?
Hey Geoff, schoolboy error, I had the 'teamMembers' set to type 'array' rather than 'reference' 😏
All good! Glad you got it worked out! 😀
Thanks for jumping to my aide so quick 🙌

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.

Was this answer helpful?