Class HasManyAssociation<S, T, SourceKey, TargetKey, TargetPrimaryKey>

One-to-many association. See Model.hasMany

Like with HasOneAssociation, the foreign key will be defined on the target model.

In the API reference below, add the name of the association to the method, e.g. for User.hasMany(Project) the getter will be user.getProjects(). If the association is aliased, use the alias instead, e.g. User.hasMany(Project, { as: 'jobs' }) will be user.getJobs().

Type Parameters

  • S extends Model = Model

    The model on which Model.hasMany has been called, on which the association methods will be added.

  • T extends Model = Model

    The model passed to Model.hasMany. This model will receive the Foreign Key attribute.

  • SourceKey extends AttributeNames<S> = any

    The name of the attribute that the foreign key in the target model will reference.

  • TargetKey extends AttributeNames<T> = any

    The name of the Foreign Key attribute on the Target model.

  • TargetPrimaryKey extends AttributeNames<T> = any

    The name of the Primary Key attribute of the Target model. Used by HasManySetAssociationsMixin & others.

Hierarchy (view full)

Constructors

Properties

isAliased: boolean
isSelfAssociation: boolean
parentAssociation: null | Association<Model<any, any>, Model<any, any>, string, NormalizedAssociationOptions<string>>

A reference to the association that created this one.

source: ModelStatic<S>
target: ModelStatic<T>

Accessors

  • get associationType(): string
  • The type of the association. One of HasMany, BelongsTo, HasOne, BelongsToMany

    Returns string

  • get name(): {
        plural: string;
        singular: string;
    }
  • Returns {
        plural: string;
        singular: string;
    }

    • plural: string
    • singular: string

Methods