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
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?
optionalpivotTable?:string
Defined in: packages/orm/src/model/relations/RelationRegistry.ts:28
manyToMany only
pivotForeignKey?
optionalpivotForeignKey?:string
Defined in: packages/orm/src/model/relations/RelationRegistry.ts:30
manyToMany only
pivotRelatedKey?
optionalpivotRelatedKey?:string
Defined in: packages/orm/src/model/relations/RelationRegistry.ts:32
manyToMany only
morphMap?
optionalmorphMap?:Record<string, () =>unknown>
Defined in: packages/orm/src/model/relations/RelationRegistry.ts:34
morphTo only: maps type discriminator string → model factory
morphTypeColumn?
optionalmorphTypeColumn?:string
Defined in: packages/orm/src/model/relations/RelationRegistry.ts:36
morphMany / morphOne / morphTo: the _type column name (e.g. "commentable_type")
through?
optionalthrough?: () =>unknown
Defined in: packages/orm/src/model/relations/RelationRegistry.ts:40
Intermediate ("through") model factory.
Returns
unknown
firstKey?
optionalfirstKey?: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?
optionalsecondKey?: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?
optionalthroughLocalKey?: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?
optionalpivotColumns?:string[]
Defined in: packages/orm/src/model/relations/RelationRegistry.ts:50
Extra pivot columns to hydrate onto each related model's pivot bag.
pivotTimestamps?
optionalpivotTimestamps?:boolean
Defined in: packages/orm/src/model/relations/RelationRegistry.ts:52
Maintain created_at / updated_at on the pivot table during attach/sync.
pivotWheres?
optionalpivotWheres?: [string,unknown][]
Defined in: packages/orm/src/model/relations/RelationRegistry.ts:54
Constant pivot constraints applied to loads and writes: [column, value][].
pivotMorphType?
optionalpivotMorphType?:string
Defined in: packages/orm/src/model/relations/RelationRegistry.ts:56
morphToMany / morphedByMany: the pivot _type column name.
pivotMorphValue?
optionalpivotMorphValue?:string
Defined in: packages/orm/src/model/relations/RelationRegistry.ts:58
morphToMany / morphedByMany: the _type value stored for this side.
withDefault?
optionalwithDefault?: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.