Skip to content

relationship

relationship<TFieldMeta, TCollectionSlug, TComponent>(options): RelationshipField<TFieldMeta, TCollectionSlug, TComponent>

Defined in: packages/core/src/fields/relationship/config.ts:46

Creates a relationship field with all defaults applied.

Stores Convex Id references pointing to documents in another registered collection. The generated Convex schema always emits v.array(v.id("collection")) regardless of hasManyhasMany is a UI-only hint that controls whether the admin picker allows one or multiple selections; it does not change the stored Convex type. A .index("by_<fieldKey>", ["<fieldKey>"]) is auto-generated for every relationship field — no explicit index property needed.

TCollectionSlug is inferred from options.collection. After running vex generate, passing an unregistered slug is a compile-time error.

Defaults applied:

  • label"" (inferred from field key by defineCollection)
  • requiredfalse
  • hasManyfalse
  • admin.hiddenfalse
  • admin.readOnlyfalse
  • admin.position"main"
  • admin.width"full"
  • admin.cellAlignment"left"

TFieldMeta extends BaseFieldMeta = BaseFieldMeta

TCollectionSlug extends string = string

Inferred from options.collection.

TComponent extends ComponentHKT = ComponentHKT

RelationshipFieldInput<TFieldMeta, TCollectionSlug, TComponent>

Relationship field config. collection is required.

RelationshipField<TFieldMeta, TCollectionSlug, TComponent>

Resolved relationship field definition with all defaults applied.

// Single reference — stores Id<"authors">
author: relationship({ collection: { slug: "authors" } })
// Multi-reference — stores Id<"tags">[]
tags: relationship({ collection: { slug: "tags" }, hasMany: true, required: false })