Documentation
    Preparing search index...

    Class ModelDefinition<M>

    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

    Index
    associations: {
        [associationName: string]: Association<
            Model<any, any>,
            Model<any, any>,
            string,
            NormalizedAssociationOptions<string>,
        >;
    } = ...
    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> = ...

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

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

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

    defaultValues: MapView<string, () => 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 ().

    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.

    • 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
          | Association<
              Model<any, any>,
              Model<any, any>,
              string,
              NormalizedAssociationOptions<string>,
          >
          | undefined

    • Returns the column name corresponding to the given attribute name.

      Parameters

      • attributeName: string

      Returns 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