Documentation / zerotal / orm / morphedByMany
Function: morphedByMany()
morphedByMany(
related,options): (_value,context) =>void
Defined in: packages/orm/src/model/decorators/morphedByMany.ts:32
Declare a polymorphic many-to-many from the "inverse" side: the shared model
reaches back to each of the owning types through the same morph pivot table
(e.g. Tag —(taggables)→ Post / Video). The property is a
ManyToMany collection with pivot methods.
Parameters
related
() => unknown
Lazy factory returning the related (owning) model class.
options
Morph name, parent pivot key, and optional pivot config.
Returns
(_value, context) => void
Example
class Tag extends BaseModel {
\@morphedByMany(() => Post, { morphName: 'taggable', parentPivotKey: 'tag_id' })
posts!: ManyToMany<Post>;
}