Documentation / zerotal / orm / manyToMany
Function: manyToMany()
manyToMany(
related,options): (_value,context) =>void
Defined in: packages/orm/src/model/decorators/manyToMany.ts:43
Declare a many-to-many relation through a pivot table (e.g. User ↔ Role
via role_user). The relation property is a ManyToMany collection that
behaves as an array yet also exposes pivot methods (attach / detach /
sync / toggle).
Parameters
related
() => unknown
Lazy factory returning the related model class.
options
Pivot table and key configuration.
Returns
(_value, context) => void
Example
class User extends BaseModel {
\@manyToMany(() => Role, {
pivotTable: 'role_user',
pivotForeignKey: 'user_id',
pivotRelatedKey: 'role_id',
})
roles!: ManyToMany<Role>;
}