Skip to main content

Function: ManyToMany()

ManyToMany(target, options): PropertyDecorator

Defined in: src/decorators/ManyToMany.ts:21

Property decorator establishing a many-to-many relationship joined via a junction table.

Parameters​

ParameterTypeDescription
target() => FunctionLambda returning the target related entity constructor.
optionsManyToManyOptionsJunction table name (through), primary foreign key, and other foreign key.

Returns​

PropertyDecorator

Usecase​

Model many-to-many associations (e.g. Students and Courses via StudentCourses junction table).

Example​

@ManyToMany(() => Tag, { through: 'post_tags', foreignKey: 'postId', otherKey: 'tagId' })
tags!: Tag[];