The goal of this class is to store the definition of a model.

It is part of the Repository Design Pattern. See https://github.com/sequelize/sequelize/issues/15389 for more details.

There is only one ModelDefinition instance per model per sequelize instance.

Type Parameters

Constructors

Properties

#attributes: Map<string, NormalizedAttributeOptions<Model<any, any>>> = ...
#attributesWithGetters: Set<string> = ...
#attributesWithSetters: Set<string> = ...
#autoIncrementAttributeName: null | string = null
#booleanAttributeNames: Set<string> = ...

Deprecated

Code should not rely on this as users can create custom attributes.

#columns: Map<string, NormalizedAttributeOptions<Model<any, any>>> = ...
#dateAttributeNames: Set<string> = ...

Deprecated

Code should not rely on this as users can create custom attributes.

#defaultValues: Map<string, (() => unknown)> = ...

Type declaration

    • (): unknown
    • Returns unknown

#indexes: IndexOptions[] = []

Final list of indexes, built by refreshIndexes

#jsonAttributeNames: Set<string> = ...
#physicalAttributes: Map<string, NormalizedAttributeOptions<Model<any, any>>> = ...
#primaryKeyAttributeNames: Set<string> = ...
#readOnlyAttributeNames: Set<string> = ...

List of attributes that cannot be modified by the user

#sequelize: Sequelize<AbstractDialect<object, object>>
#versionAttributeName: undefined | string

The name of the attribute that records the version of the model instance.

#virtualAttributeNames: Set<string> = ...
associations: {
    [associationName: string]: Association;
} = ...

Type declaration

attributes: MapView<string, NormalizedAttributeOptions<Model<any, any>>> = ...

The list of attributes that have been normalized.

This map is fully frozen and cannot be modified directly. Modify rawAttributes then call refreshAttributes instead.

attributesWithGetters: SetView<string> = ...
attributesWithSetters: SetView<string> = ...
booleanAttributeNames: SetView<string> = ...

Deprecated

Code should not rely on this as users can create custom attributes.

columns: MapView<string, NormalizedAttributeOptions<Model<any, any>>> = ...
dateAttributeNames: SetView<string> = ...

Deprecated

Code should not rely on this as users can create custom attributes.

defaultValues: MapView<string, (() => unknown)> = ...

Type declaration

    • (): unknown
    • Returns unknown

jsonAttributeNames: SetView<string> = ...
model: ModelStatic<M>
physicalAttributes: MapView<string, NormalizedAttributeOptions<Model<any, any>>> = ...

The list of attributes that actually exist in the database, as opposed to virtualAttributeNames.

primaryKeysAttributeNames: SetView<string> = ...
rawAttributes: {
    [attributeName: string]: AttributeOptions<M>;
}

The list of attributes that have not been normalized. This list can be mutated. Call refreshAttributes to update the normalized attributes ().

Type declaration

readOnlyAttributeNames: SetView<string> = ...

List of attributes that cannot be modified by the user (read-only)

timestampAttributeNames: TimestampAttributes = ...

Records which attributes are the different built-in timestamp attributes

virtualAttributeNames: SetView<string> = ...

The list of attributes that do not really exist in the database.

Accessors

Methods

  • Follows the association path and returns the association at the end of the path. For instance, say we have a model User, associated to a model Profile, associated to a model Address.

    If we call User.modelDefinition.getAssociation(['profile', 'address']), we will get the association named address in the model Profile. If we call User.modelDefinition.getAssociation(['profile']), we will get the association named profile in the model User.

    Parameters

    • associationPath: string | readonly string[]

    Returns undefined | Association<Model<any, any>, Model<any, any>, string, NormalizedAssociationOptions<string>>

  • Returns the column name corresponding to the given attribute name if it exists, otherwise returns the attribute name.

    ⚠️ Using this method is highly discouraged. Users should specify column names & attribute names separately, to prevent any ambiguity.

    Parameters

    • attributeName: string

    Returns string