Fields
Relation and join
Point to other documents, and list the documents that point back.
A relation stores the id of another document, like the author of a post. A join is the other side: it lists the documents whose relation points here, like the posts of an author.

Example
cms/collections/posts.ts
export const posts = defineCollection({
fields: {
title: { type: "text", required: true },
author: { type: "relation", collection: "authors" },
tags: { type: "relation", collection: "tags", many: true },
},
});
A read loads the related documents in place of the ids:
const post = await cms.findOne("posts", { where: { slug } });
post?.author?.name; // string
post?.tags?.map((tag) => tag.title);
const raw = await cms.findOne("posts", { where: { slug }, populate: false });
raw?.author; // string, the id
Render it
<p>By {post.author?.name ?? "Unknown"}</p>
<ul>
{post.tags?.map((tag) => <li>{tag.title}</li>)}
</ul>
<template>
<p>By {{ post.author?.name ?? "Unknown" }}</p>
<ul>
<li v-for="tag in post.tags" :key="tag.id">{{ tag.title }}</li>
</ul>
</template>
<>
<p>By {post.author?.name ?? "Unknown"}</p>
<ul>
{post.tags?.map((tag) => (
<li key={tag.id}>{tag.title}</li>
))}
</ul>
</>
How deep a read loads, and how to keep the loaded documents small, is in Relations.
- Each write checks that every id exists. A document cannot point to itself.
- A
manyrelation keeps its order and rejects duplicates. - A
relationworks at the top level, in groups and in list items, in collections and globals. It can only point to collections. - A typo in
collectionis a type error intenon.config.ts.
You can filter by a single top-level relation: cms.find("posts", { where: { author: id } }). Filters do not accept many relations, relations in groups or joins.
Join
A join stores nothing. It lists the documents of collection whose relation on points to this document:
cms/collections/authors.ts
export const authors = defineCollection({
titleField: "name",
fields: {
name: { type: "text", required: true },
posts: { type: "join", collection: "posts", on: "author" },
},
});

A read loads a join only when you name it:
const author = await cms.findById("authors", id, { populate: { posts: true } });
author?.posts?.map((post) => post.title);
<h2>Posts by {author.name}</h2>
<ul>
{author.posts?.map((post) => (
<li><a href={`/posts/${post.slug}`}>{post.title}</a></li>
))}
</ul>
<template>
<h2>Posts by {{ author.name }}</h2>
<ul>
<li v-for="post in author.posts" :key="post.id">
<NuxtLink :to="`/posts/${post.slug}`">{{ post.title }}</NuxtLink>
</li>
</ul>
</template>
<>
<h2>Posts by {author.name}</h2>
<ul>
{author.posts?.map((post) => (
<li key={post.id}>
<a href={`/posts/${post.slug}`}>{post.title}</a>
</li>
))}
</ul>
</>
- A
joinworks only at the top level of a collection. oncan name a relation inside a group, likeseo.image.required,default,hiddenandprivatedo not apply, because a join stores nothing.
Options
required, at least one. Default false.{ name: true, avatar: true }. See Keep related documents small."restrict" for a required relation, otherwise "set-null". See When a document is deleted.The options of a join:
collection that points here, like author or seo.image.Every field type takes these options. See the fields overview for examples and validation.
label
string | { en, de, … }
The label in the admin. Defaults to the key. Pass an object to translate it.
description
string | { en, de, … }
Help text below the input.
required
boolean
The value MUST be present. A list needs at least one item.
default
value | ({ user, … }) => value
The value of a new document, when the field is missing. A plain value also fills the new form in the admin. A function, like
({ user }) => user?.id, runs on the server only.unique
boolean
No other document of the collection has the same value. See Validation .
validate
(value, args) => true | string
Your own check. See Your own checks .
condition
Condition
Show the field only when other values match. See Conditions .
private
boolean
Public reads leave the value out. Signed-in users and server code see it.
access
{ read, create, update }
Who can read and write this field. See Access control .
localized
false
In a localized collection, every field is stored per language. Localization .
false shares this field between languages. Only on top-level fields. See hooks
FieldHooks
Functions that run for this field on every write and read, before the collection's hooks. See Hooks .
hidden
boolean
Admin only
The admin does not show the input. The value still saves. Use it for values a hook sets.
readOnly
boolean
Admin only
The admin shows the input disabled. Code and hooks can still write it.
width
"1/4" | "1/3" | "1/2" | "2/3" | "3/4" | "full"
Admin only
The share of the row the field takes. Fields next to each other fill a row. In a narrow form, every field takes the full width. Default
"full".separator
true | string
Admin only
A line above the field, to break up a long form. A string adds a heading above the line.
tab
string | string[]
Admin only
The tab that shows this field. Define the tabs with
tabs on the collection, global, group or list item.fieldset
string
Admin only
The box that holds this field. Define the boxes with
fieldsets.
