Documentation
    Preparing search index...

    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

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

    A reference to the association that created this one.

    source: ModelStatic<S>
    target: ModelStatic<T>
    • get as(): string

      The identifier of the relation on the source model.

      Returns string

    • get associationType(): string

      The type of the association. One of HasMany, BelongsTo, HasOne, BelongsToMany

      Returns string

    • get foreignKey(): TargetKey

      The name of the foreign key attribute used by this association.

      Returns TargetKey

    • get identifierField(): string

      The column name of the foreign key (on the target model)

      Returns string

    • get isMultiAssociation(): boolean

      Returns boolean

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

      Returns { plural: string; singular: string }

    • get rootAssociation(): Association

      Creating an associations can automatically create other associations. This returns the initial association that caused the creation of the descendant associations.

      Returns Association

    • get sourceKey(): SourceKey

      The name of the attribute the foreign key points to.

      This key is on the Source Model. The Association.foreignKey is on the Target Model.

      Returns SourceKey

    • get sourceKeyField(): string

      Returns string

    • get isMultiAssociation(): boolean

      Returns boolean