Skip to content

feat(schema): add relation editor option - #3840

Open
nadaamd wants to merge 1 commit into
nuxt:mainfrom
nadaamd:feat/relation-editor-option
Open

feat(schema): add relation editor option#3840
nadaamd wants to merge 1 commit into
nuxt:mainfrom
nadaamd:feat/relation-editor-option

Conversation

@nadaamd

@nadaamd nadaamd commented Aug 24, 2026

Copy link
Copy Markdown

🔗 Linked issue

No issue on this repo; happy to open one if you would rather have the discussion here.

❓ Type of change

  • 📖 Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

Types only — adds 'relation' to EditorOptions.input and a relation?: RelationOptions
option, so a string field can declare that it references a document of another
collection:

author: property(z.string()).editor({
  input: 'relation',
  relation: { collection: 'authors', labelField: 'name' },
})

The picker itself lives in Studio (nuxt-content/nuxt-studio#548), which renders a
searchable list of the referenced collection's documents and stores the chosen
document's slug. Editors currently have to type that slug by hand.

Nothing here changes at runtime. .editor() already merges its whole
argument into _def.editor (src/utils/schema/zod3.ts:25, and the same spread in
the property() proxy for zod4/valibot), and toJSONSchema's override copies
it verbatim into $content.editor. So relation already reaches Studio today —
this only stops input: 'relation' from being a type error, which is otherwise
a cast at every call site.

RelationOptions is exported through export type * from './schema', so
consumers can type their own metadata against it.

Additive and non-breaking: one new member on an existing string union, one new
optional key. ConfigInputsTypes in src/utils/preview/data.ts is deliberately
untouched — that union is for app.config.ts @previewInput tags, a separate
feature from collection-schema editor metadata.

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

On docs: docs/content/docs/2.collections/4.validators.md intentionally does not
enumerate the available inputs — it points at the Studio docs for the mapping.
The relation option is documented there instead, in
nuxt-content/nuxt-studio#548. Glad to add a short section here too if you would
prefer the list to live in both places.

Lets a string field declare that it references a document of another
collection, so Studio can render a picker instead of a free-text input.

Types only: `.editor()` already merges its whole argument into the generated
schema, so `relation` reaches Studio today — this stops `input: 'relation'`
from needing a cast at every call site.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented Aug 24, 2026

Copy link
Copy Markdown

@nadaamd is attempting to deploy a commit to the Nuxt Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Aug 24, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f0ab2e5b-c905-49d7-b892-c9f04ca8e06a

📥 Commits

Reviewing files that changed from the base of the PR and between 8841abc and 43aeeb1.

📒 Files selected for processing (1)
  • src/types/schema.ts

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The public schema now accepts relation as an EditorOptions.input value. EditorOptions includes a relation property. The new RelationOptions interface defines a required collection and optional value and label field selectors.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 43aee

This is a localized, additive type change with no runtime behavior impact; no actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring check was indeterminate for this PR — some files could not be analyzed in time. Not blocking.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely identifies the addition of the relation editor option, which is the main change.
Description check ✅ Passed The description accurately explains the new relation schema option, its type-only scope, and its non-breaking behavior.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Aug 24, 2026

Copy link
Copy Markdown
npm i https://pkg.pr.new/@nuxt/content@3840

commit: 43aeeb1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant