Skip to content

relationship

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

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

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 hasMany — hasMany 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.

TTargetSlug 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)
  • required — false
  • hasMany — false
  • admin.hidden — false
  • admin.readOnly — false
  • admin.position — "main"
  • admin.width — "100%"
  • admin.cellAlignment — "left"

TCollectionSlug extends string = string

TFieldKey extends string = never

TFieldMeta extends BaseFieldMeta = BaseFieldMeta

TTargetSlug extends string = string

Inferred from options.collection.

TComponent extends ComponentHKT = ComponentHKT

RelationshipFieldInput<TCollectionSlug, TFieldKey, TFieldMeta, TTargetSlug, TComponent>

Relationship field config. collection is required.

RelationshipField<TCollectionSlug, TFieldMeta, TTargetSlug, 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 })