Skip to content

RelationshipFieldInput

Defined in: packages/core/src/fields/relationship/types.ts:107

Configuration input for a relationship() field.

Stores Convex Id references to documents in another registered collection. The Convex schema always uses v.array(v.id("slug")) regardless of hasMany. hasMany is a UI-only hint — false shows a single-selection picker, true shows a multi-selection picker. TCollectionSlug is inferred from the collection option — after running vex generate, invalid slugs are a compile-time error.

Defaults applied by relationship():

{
type: "relationship",
label: "", // inferred from the field key by defineCollection
required: false,
hasMany: false, // single-select picker in the admin UI; schema is always v.array(v.id())
admin: {
hidden: false,
readOnly: false,
position: "main",
width: "full",
cellAlignment: "left",
}
}
@typeParam TCollectionSlug - The target collection slug. Inferred from `collection`.
Defaults to `CollectionSlug` (the full union after `vex generate`).
@example
```ts
// Single reference
author: relationship({ collection: { slug: "authors" } })
// Multi-reference
tags: relationship({ collection: { slug: "tags" }, hasMany: true })

@see {@link RelationshipField} for the resolved output type @see {@link relationship} for the config function @see {@link CollectionSlug} for the valid slug union

TFieldMeta extends object = { }

TCollectionSlug extends CollectionSlug = CollectionSlug

TComponent extends ComponentHKT = ComponentHKT

optional admin?: FieldAdminConfigInput & RelationshipFieldAdminInput<TCollectionSlug, TComponent>

Defined in: packages/core/src/fields/relationship/types.ts:123

Admin UI configuration for this field.

BaseFieldInput.admin


collection: object

Defined in: packages/core/src/fields/relationship/types.ts:113

Target collection reference. The slug must match a registered collection in defineConfig.

slug: TCollectionSlug

The slug of the collection this field links to. Must be a registered collection slug.


optional defaultValue?: unknown

Defined in: packages/core/src/fields/baseTypes.ts:207

Pre-filled value shown in the admin form when creating a new field. Does not apply to database values

BaseFieldInput.defaultValue


optional description?: string

Defined in: packages/core/src/fields/baseTypes.ts:194

Semantic description of the field. Used in three places:

  1. Helper text rendered below the field input in the admin form UI.
  2. As the Zod .meta({ description }) value for form validation.
  3. As the JSDoc comment on the generated document interface property.

To write a separate JSDoc comment, use interfaceDescription in addition.

BaseFieldInput.description


optional hasMany?: boolean

Defined in: packages/core/src/fields/relationship/types.ts:122

Whether this field stores multiple references. false stores a single Id, true stores Id[].

false

optional index?: string

Defined in: packages/core/src/fields/baseTypes.ts:220

Create a database index on this field. The string value becomes the index name in Convex.

slug: { type: "text", index: "by_slug", required: true }
// Generates: .index("by_slug", ["slug"])

BaseFieldInput.index


optional interfaceDescription?: string

Defined in: packages/core/src/fields/baseTypes.ts:196

The JSDoc comment on the generated document interface property

BaseFieldInput.interfaceDescription


optional label?: string

Defined in: packages/core/src/fields/baseTypes.ts:185

Display label for the field in the admin form.

BaseFieldInput.label


optional meta?: TFieldMeta

Defined in: packages/core/src/fields/baseTypes.ts:221

BaseFieldInput.meta


optional required?: boolean

Defined in: packages/core/src/fields/baseTypes.ts:202

Whether this field is required.

Default: false

BaseFieldInput.required