Class BelongsToAssociation<S, T, SourceKey, TargetKey>

One-to-one association See Model.belongsTo

This is almost the same as HasOneAssociation, but the foreign key will be defined on the source model.

In the API reference below, add the name of the association to the method, e.g. for User.belongsTo(Project) the getter will be user.getProject().

Type Parameters

  • S extends Model = Model

    The model on which Model.belongsTo has been called, on which the association methods, as well as the foreign key attribute, will be added.

  • T extends Model = Model

    The model passed to Model.belongsTo.

  • SourceKey extends AttributeNames<S> = any

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

  • TargetKey extends AttributeNames<T> = any

    The name of the attribute that the foreign key in the source model will reference, typically the Primary Key.

Hierarchy (view full)

Constructors

Properties

foreignKey: SourceKey
identifierField: string

The column name of the foreign key

inverse: undefined | Association<Model<any, any>, Model<any, any>, string, NormalizedAssociationOptions<string>>
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>
targetKey: TargetKey

The name of the attribute the foreign key points to. In belongsTo, this key is on the Target Model, instead of the Source Model (unlike HasOneAssociation.sourceKey). The Association.foreignKey is on the Source Model.

targetKeyField: string

The column name of the target key

targetKeyIsPrimary: boolean

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