Interface ModelOptions<M>

Options for model definition.

Used by define and init

See

https://sequelize.org/docs/v7/core-concepts/model-basics/

Type Parameters

Hierarchy

Properties

charset?: string

The charset to use for the model

collate?: string

The collation for model's table

comment?: string

A comment for the table.

MySQL, PG only.

createdAt?: string | boolean

Override the name of the createdAt attribute if a string is provided, or disable it if false. timestamps must be true.

Not affected by underscored setting.

defaultScope?: FindOptions<Attributes<M>>

Define the default search scope to use for this model. Scopes have the same form as the options passed to find / findAll.

See https://sequelize.org/docs/v7/other-topics/scopes/ to learn more about scopes.

deletedAt?: string | boolean

Override the name of the deletedAt attribute if a string is provided, or disable it if false. timestamps must be true. paranoid must be true.

Not affected by underscored setting.

engine?: string

The name of the database storage engine to use (e.g. MyISAM, InnoDB).

MySQL, MariaDB only.

freezeTableName?: boolean

If true, sequelize will use the name of the Model as-is as the name of the SQL table. If false, the name of the table will be pluralised (and snake_cased if underscored is true).

This option has no effect if tableName is set.

Default

false

getterMethods?: ModelGetterOptions<M>

Allows defining additional getters that will be available on model instances.

hasTrigger?: boolean

Indicates if the model's table has a trigger associated with it.

Default

false

hooks?: {
    afterAssociate?: any;
    afterBulkCreate?: any;
    afterBulkDestroy?: any;
    afterBulkRestore?: any;
    afterBulkSync?: any;
    afterBulkUpdate?: any;
    afterCreate?: any;
    afterDestroy?: any;
    afterFind?: any;
    afterQuery?: any;
    afterRestore?: any;
    afterSave?: any;
    afterSync?: any;
    afterUpdate?: any;
    afterUpsert?: any;
    afterValidate?: any;
    beforeAssociate?: any;
    beforeBulkCreate?: any;
    beforeBulkDestroy?: any;
    beforeBulkRestore?: any;
    beforeBulkSync?: any;
    beforeBulkUpdate?: any;
    beforeCount?: any;
    beforeCreate?: any;
    beforeDestroy?: any;
    beforeFind?: any;
    beforeFindAfterExpandIncludeAll?: any;
    beforeFindAfterOptions?: any;
    beforeQuery?: any;
    beforeRestore?: any;
    beforeSave?: any;
    beforeSync?: any;
    beforeUpdate?: any;
    beforeUpsert?: any;
    beforeValidate?: any;
    validationFailed?: any;
}

Add hooks to the model. Hooks will be called before and after certain operations.

This can also be done through addHook, or the individual hook methods such as Model.afterQuery. Each property can either be a function, or an array of functions.

See

https://sequelize.org/docs/v7/other-topics/hooks/

Type declaration

  • afterAssociate?:function
    • afterBulkCreate?:function
      • afterBulkDestroy?:function
        • afterBulkRestore?:function
          • afterBulkSync?:function
            • afterBulkUpdate?:function
              • afterCreate?:function
                • afterDestroy?:function
                  • afterFind?:function
                    • afterQuery?:function
                      • afterRestore?:function
                        • afterSave?:function
                          • afterSync?:function
                            • afterUpdate?:function
                              • afterUpsert?:function
                                • afterValidate?:function
                                  • beforeAssociate?:function
                                    • beforeBulkCreate?:function
                                      • beforeBulkDestroy?:function
                                        • beforeBulkRestore?:function
                                          • beforeBulkSync?:function
                                            • beforeBulkUpdate?:function
                                              • beforeCount?:function
                                                • beforeCreate?:function
                                                  • beforeDestroy?:function
                                                    • beforeFind?:function
                                                      • beforeFindAfterExpandIncludeAll?:function
                                                        • beforeFindAfterOptions?:function
                                                          • beforeQuery?:function
                                                            • beforeRestore?:function
                                                              • beforeSave?:function
                                                                • beforeSync?:function
                                                                  • beforeUpdate?:function
                                                                    • beforeUpsert?:function
                                                                      • beforeValidate?:function
                                                                        • validationFailed?:function
                                                                          indexes?: readonly IndexOptions[]

                                                                          Indexes for the provided database table

                                                                          initialAutoIncrement?: string

                                                                          Set the initial AUTO_INCREMENT value for the table in MySQL.

                                                                          modelName?: string

                                                                          The name of the model.

                                                                          If not set, the name of the class will be used instead. You should specify this option if you are going to minify your code in a way that may mangle the class name.

                                                                          An object with two attributes, singular and plural, which are used when this model is associated to others.

                                                                          noPrimaryKey?: boolean

                                                                          Sequelize will automatically add a primary key called id if no primary key has been added manually.

                                                                          Set to false to disable adding that primary key.

                                                                          Default

                                                                          false

                                                                          omitNull?: boolean

                                                                          Don't persist null values. This means that all columns with null values will not be saved.

                                                                          Default

                                                                          false

                                                                          paranoid?: boolean

                                                                          If true, calling destroy will not delete the model, but will instead set a deletedAt timestamp.

                                                                          This options requires timestamps to be true. The deletedAt column can be customized through deletedAt.

                                                                          Default

                                                                          false

                                                                          schema?: string

                                                                          The database schema in which this table will be located.

                                                                          schemaDelimiter?: string

                                                                          More scopes, defined in the same way as defaultScope above. See scope for more information about how scopes are defined, and what you can do with them.

                                                                          See https://sequelize.org/docs/v7/other-topics/scopes/ to learn more about scopes.

                                                                          setterMethods?: ModelSetterOptions<M>

                                                                          Allows defining additional setters that will be available on model instances.

                                                                          tableName?: string

                                                                          The name of the table in SQL.

                                                                          Default

                                                                          The modelName, pluralized, unless freezeTableName is true, in which case it uses model name verbatim.

                                                                          timestamps?: boolean

                                                                          Adds createdAt and updatedAt timestamps to the model.

                                                                          Default

                                                                          true

                                                                          underscored?: boolean

                                                                          If true, Sequelize will snake_case the name of columns that do not have an explicit value set (using field). The name of the table will also be snake_cased, unless tableName is set, or freezeTableName is true.

                                                                          Default

                                                                          false

                                                                          updatedAt?: string | boolean

                                                                          Override the name of the updatedAt attribute if a string is provided, or disable it if false. timestamps must be true.

                                                                          Not affected by underscored setting.

                                                                          An object of model wide validations. Validations have access to all model values via this. If the validator function takes an argument, it is assumed to be async, and is called with a callback that accepts an optional error.

                                                                          version?: string | boolean

                                                                          Enable optimistic locking. When enabled, sequelize will add a version count attribute to the model and throw an OptimisticLockingError error when stale instances are saved.

                                                                          • If string: Uses the named attribute.
                                                                          • If boolean: Uses version.

                                                                          Default

                                                                          false

                                                                          Generated using TypeDoc