Skip to content

postgrelize / BelongsToMany

Variable: BelongsToMany ​

BelongsToMany: (target, through, options?) => ModelPropertyDecorator

Defined in: src/decorators/association-decorators.ts:32

Adds a belongsToMany association through a junction model. The junction model's @ForeignKey attributes give foreignKey (to this model) and otherKey (to the target) unless options sets them.

Parameters ​

target ​

ModelGetter

Function returning the associated model.

through ​

NonNullable<string | Readonly<{ model: string | ModelStatic<AnyModel>; scope?: Readonly<Record<string, unknown>>; }> | ModelGetter | undefined>

Junction table name, function returning the junction model, or { model, scope }.

options? ​

Omit<BelongsToManyOptions, "through">

Association options (foreignKey, otherKey, …).

Returns ​

ModelPropertyDecorator

An attribute decorator.

Example ​

ts
class Post extends Model {
  @BelongsToMany(() => Tag, 'post_tags')
  tags!: Tag[];
}

Released under the MIT License.