Documentation
    Preparing search index...

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

    One-to-one association. See Model.hasOne

    This is almost the same as BelongsToAssociation, but 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.hasOne(Project) the getter will be user.getProject().

    Type Parameters

    Hierarchy (View Summary)

    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 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 }

    • 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