You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/content/docs/plugins/cms.mdx
+48-2Lines changed: 48 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1315,10 +1315,10 @@ export async function generateStaticParams() {
1315
1315
1316
1316
### Server-side mutation — `createContentItem`
1317
1317
1318
-
In addition to read-only getters, the CMS plugin exposes a **mutation function** for creating content items directly from server-side code.
1318
+
In addition to read-only getters, the CMS plugin exposes a **mutation function** for creating content items directly from server-side code. This is the recommended path for seeds, imports, and scheduled jobs.
1319
1319
1320
1320
<Callouttype="warn">
1321
-
**`createContentItem` bypasses authorization hooks and Zod schema validation.** Hooks such as `onBeforeCreate` and `onAfterCreate` are **not** called, and the data payload is stored as-is without running the content type's schema validation. The caller is responsible for providing valid, relation-free data and for any access-control checks. For relation fields or schema validation, use the HTTP endpoint instead.
1321
+
**`createContentItem` bypasses authorization hooks and Zod schema validation.** Hooks such as `onBeforeCreate` and `onAfterCreate` are **not** called, and the data payload is stored as-is without running the content type's schema validation. The caller is responsible for providing validdata and for any access-control checks. Inline `_new`relation creation is not supported — pre-create related items and pass their IDs. For schema validation or inline `_new` creation, use the HTTP endpoint instead.
By default, `createContentItem` only writes the item's JSON payload — it does **not** populate the `contentRelation` junction table. This is a no-op for content types without relations, but for content types with `belongsTo` / `hasMany` / `manyToMany` fields it means:
1354
+
1355
+
- The admin UI's "Related Items" / inverse-relations panel will not discover the item.
1356
+
-`useContentByRelation`, `getContentByRelation`, and `*/populated` endpoints will not return it.
1357
+
- Only the JSON `{ id: "..." }` reference on the item itself is persisted.
1358
+
1359
+
Pass `{ syncRelations: true }` to also persist relation fields into the junction table — the same behavior the HTTP `POST /content/:typeSlug` route provides, minus inline `_new` creation.
Enable `syncRelations: true` whenever the content type has relation fields — especially in seed scripts. Without it, seeded items appear correctly on their own detail page but are invisible to inverse-relation queries, so the admin "Related Items" panel and any `by-relation` filter will silently show zero results.
1382
+
</Callout>
1383
+
1384
+
The same option is available on the direct import:
0 commit comments