Interface BelongsToOptions<SourceKey, TargetKey>

Options provided when associating models with belongsTo relationship

See

Association class belongsTo method

interface BelongsToOptions<SourceKey, TargetKey> {
    as?: string | {
        plural: string;
        singular: string;
    };
    foreignKey?: SourceKey | ForeignKeyOptions<SourceKey>;
    foreignKeyConstraints?: boolean;
    hooks?: boolean;
    inverse?: {
        as?: string;
        scope?: AssociationScope;
        type: "hasOne" | "hasMany";
    };
    scope?: AssociationScope;
    targetKey?: TargetKey;
}

Type Parameters

  • SourceKey extends string
  • TargetKey extends string

Hierarchy (view full)

Properties

as?: string | {
    plural: string;
    singular: string;
}

The alias of this model, in singular form. See also the name option passed to sequelize.define. If you create multiple associations between the same tables, you should provide an alias to be able to distinguish between them. If you provide an alias when creating the association, you should provide the same alias when eager loading and when getting associated models. Defaults to the singularized name of target

Type declaration

  • plural: string
  • singular: string

The configuration of the foreign key Attribute. See Sequelize#define or Model.init for more information about the syntax.

Using a string is equivalent to passing a ForeignKeyOptions object with the ForeignKeyOptions.name option set.

foreignKeyConstraints?: boolean

Should ON UPDATE, ON DELETE, and REFERENCES constraints be enabled on the foreign key.

hooks?: boolean

If false the applicable hooks will not be called. The default value depends on the context.

Default

true
inverse?: {
    as?: string;
    scope?: AssociationScope;
    type: "hasOne" | "hasMany";
}

Type declaration

targetKey?: TargetKey

The name of the field to use as the key for the association in the target table. Defaults to the primary key of the target table