Skip to main content
zerotal

Documentation


Documentation / @zerotal/orm / index / RelationMetadata

Interface: RelationMetadata

Defined in: packages/orm/src/model/relations/RelationRegistry.ts:22

Normalized descriptor for a single relation, produced by a relation decorator and stored in the relationRegistry. The ModelQueryBuilder reads it to build eager-load, existence and aggregate queries. Which fields are meaningful depends on type (see the per-field notes below).

Properties

type

type: RelationType

Defined in: packages/orm/src/model/relations/RelationRegistry.ts:23


related: () => unknown

Defined in: packages/orm/src/model/relations/RelationRegistry.ts:24

Returns

unknown


foreignKey

foreignKey: string

Defined in: packages/orm/src/model/relations/RelationRegistry.ts:25


localKey

localKey: string

Defined in: packages/orm/src/model/relations/RelationRegistry.ts:26


pivotTable?

optional pivotTable?: string

Defined in: packages/orm/src/model/relations/RelationRegistry.ts:28

manyToMany only


pivotForeignKey?

optional pivotForeignKey?: string

Defined in: packages/orm/src/model/relations/RelationRegistry.ts:30

manyToMany only


pivotRelatedKey?

optional pivotRelatedKey?: string

Defined in: packages/orm/src/model/relations/RelationRegistry.ts:32

manyToMany only


morphMap?

optional morphMap?: Record<string, () => unknown>

Defined in: packages/orm/src/model/relations/RelationRegistry.ts:34

morphTo only: maps type discriminator string → model factory


morphTypeColumn?

optional morphTypeColumn?: string

Defined in: packages/orm/src/model/relations/RelationRegistry.ts:36

morphMany / morphOne / morphTo: the _type column name (e.g. "commentable_type")


through?

optional through?: () => unknown

Defined in: packages/orm/src/model/relations/RelationRegistry.ts:40

Intermediate ("through") model factory.

Returns

unknown


firstKey?

optional firstKey?: string

Defined in: packages/orm/src/model/relations/RelationRegistry.ts:42

FK on the through table pointing back to the parent (e.g. country_id on users).


secondKey?

optional secondKey?: string

Defined in: packages/orm/src/model/relations/RelationRegistry.ts:44

FK on the related table pointing to the through model (e.g. user_id on posts).


throughLocalKey?

optional throughLocalKey?: string

Defined in: packages/orm/src/model/relations/RelationRegistry.ts:46

Local key on the through model the related FK references. Defaults to 'id'.


pivotColumns?

optional pivotColumns?: string[]

Defined in: packages/orm/src/model/relations/RelationRegistry.ts:50

Extra pivot columns to hydrate onto each related model's pivot bag.


pivotTimestamps?

optional pivotTimestamps?: boolean

Defined in: packages/orm/src/model/relations/RelationRegistry.ts:52

Maintain created_at / updated_at on the pivot table during attach/sync.


pivotWheres?

optional pivotWheres?: [string, unknown][]

Defined in: packages/orm/src/model/relations/RelationRegistry.ts:54

Constant pivot constraints applied to loads and writes: [column, value][].


pivotMorphType?

optional pivotMorphType?: string

Defined in: packages/orm/src/model/relations/RelationRegistry.ts:56

morphToMany / morphedByMany: the pivot _type column name.


pivotMorphValue?

optional pivotMorphValue?: string

Defined in: packages/orm/src/model/relations/RelationRegistry.ts:58

morphToMany / morphedByMany: the _type value stored for this side.


withDefault?

optional withDefault?: boolean | Record<string, unknown> | ((model) => void)

Defined in: packages/orm/src/model/relations/RelationRegistry.ts:62

belongsTo withDefault: true, an attributes object, or a builder callback.