Setting the file. One moment.
Skill 02 · Content Modeling Best Practices
Subchapter 2.2
references/reference-vs-embedding.mdMarkdown2 KBView on GitHub
When should content be linked (referenced) vs copied (embedded)? This decision affects reusability, query complexity, and editing workflows.
| Aspect | Reference | Embedded Object |
|---|---|---|
| Reusability | ✅ Shared across documents | ❌ Copied per document |
| Single source | ✅ Update once, reflects everywhere | ❌ Must update each copy |
| Query complexity | Requires joins/expansion | Inline, simpler queries |
| Editing UX | Separate editing interface | All fields in one place |
| Independence | Can exist on its own | Only exists within parent |
Use references when content:
Examples:
Use embedded objects when content:
Examples:
// Reference: Author is reusable
defineField({
name: 'author',
type: 'reference',
to: [{ type: 'author' }]
})
// Embedded: SEO is page-specific
defineField({
name: 'seo',
type: 'object',
fields: [
defineField({ name: 'title', type: 'string' }),
defineField({ name: 'description', type: 'text' })
]
})Sometimes you want both: a reference for the canonical data, plus embedded overrides.
defineField({
name: 'featuredProduct',
type: 'object',
fields: [
defineField({
name: 'product',
type: 'reference',
to: [{ type: 'product' }]
}),
defineField({
name: 'overrideTitle',
type: 'string',
description: 'Optional: Override the product title for this context'
}),
]
})Query uses coalesce(overrideTitle, product->title).