Skip to main content
zerotal

Documentation


Documentation / @zerotal/orm / index / morphTo

Function: morphTo()

morphTo(options): (_value, context) => void

Defined in: packages/orm/src/model/decorators/morphTo.ts:39

Declare the inverse side of a polymorphic relation: this model belongs to one of several possible parent types, resolved at load time from the _type discriminator column via the morphMap (e.g. a Comment belongs to a Post or Video through commentable).

Parameters

options

MorphToOptions

The type-to-model map plus optional column-name overrides.

Returns

(_value, context) => void

Example

class Comment extends BaseModel {
  \@morphTo({ morphMap: { Post: () => Post, Video: () => Video } })
  commentable!: MorphTo<Post | Video>;
}