Reference Field Reference
fields.reference()
Deprecated: use fields.related() instead. Reference to other Strife documents, scoped by target type(s). Not localizable.
Deprecated: use fields.related() instead, from @strifeapp/strife 2.0.0. It maps to the same editor (str-related), so values already saved in the field keep working after the switch. Keep the key and to, and drop multiple: true. Otherwise set size: 1 if the field allows one document in Studio, and leave size out if it allows several (a template last pushed with @strifeapp/strife 1.7 or older). See Switching from fields.reference(). From @strifeapp/cli 0.1.20, strife push and strife typegen validate refuse a schema with a fields.reference() field when the project's @strifeapp/strife is 2.0.0 or later, and warn with an older one.
Reference to other Strife documents. Maps to editor { name: 'str-related', type: 'related' }. Not localizable — the content index never treats relations as per-locale scalars.
Stored as an array of document ids or { id, displayName } objects, and both are read: the new interface saves ids, and the classic interface saves { id, displayName } copies. Infer<> gives ContentRef[]. At read time the content index projects each reference into the full target document, so strife typegen emits Target[] instead.
Example
fields.reference({
label: 'Author',
to: 'author',
})
fields.reference({
label: 'Related posts',
to: ['article', 'video-post'],
multiple: true,
})Options
| Option | Type | Required | Description |
|---|---|---|---|
label | string | Yes | Label shown to editors in Strife Studio. |
to | string | readonly string[] | Yes | The defineType name(s) this reference may point to. Resolves to the editor's allowedCollections via the default collection rule (toPlural(toPascalCase(name))) and drives the generated read type (Target[]). |
propertyName | string | No | Override the stored property name. |
multiple | boolean | No | Allow selecting more than one document in the editor (wire multiSelect). Defaults to false — always compiled explicitly, so omitting it means single-select. Does not change the read type; the index always returns an array either way. |
Studio-built templates are a separate concern. fields.reference() always compiles an explicit multiSelect: true/false, so anything pushed through defineType/strife push is safe by default. A Related field built by hand in Strife Studio can still end up with no multiSelect attribute saved at all, in which case the str-related editor component's own default (multiSelect = true) applies — that's a separate frontend gap, not yet fixed, unrelated to this DSL.
If a target defineType overrides its own collection, the derived allowedCollections on this field (a picker-UI hint only) won't match it, and nothing warns about it. The generated read type is correct either way; only the Studio picker's collection scoping is affected.
Output type
Write shape: ContentRef[] ({ id, displayName? }). Generated read shape (via strife typegen): Target[], the fully projected target document(s).
See also
fields.related()— its replacement, on the same editor.- Related — the same editor, documented from the Strife Studio UI side.
fields.references()— a different editor (str-references): a sized list scoped by template name (allow) rather than by collection (to).