Options
All
  • Public
  • Public/Protected
  • All
Menu

Options for model definition

see

Sequelize.define

Type parameters

  • TInstance

Hierarchy

  • DefineOptions

Index

Properties

Optional charset

charset: string

Optional classMethods

classMethods: Object

Provide functions that are added to the model (Model). If you override methods provided by sequelize, you can access the original method using this.constructor.prototype, e.g. this.constructor.prototype.find.apply(this, arguments)

Optional collate

collate: string

Optional comment

comment: string

Finaly you can specify a comment for the table in MySQL and PG

Optional createdAt

createdAt: string | boolean

Override the name of the createdAt column if a string is provided, or disable it if false. Timestamps must be true. Not affected by underscored setting.

Optional defaultScope

defaultScope: FindOptions

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

Optional deletedAt

deletedAt: string | boolean

Override the name of the deletedAt column if a string is provided, or disable it if false. Timestamps must be true. Not affected by underscored setting.

Optional engine

engine: string

You can also change the database engine, e.g. to MyISAM. InnoDB is the default.

Optional freezeTableName

freezeTableName: boolean

If freezeTableName is true, sequelize will not try to alter the DAO name to get the table name. Otherwise, the dao name will be pluralized. Default false.

Optional getterMethods

Provide getter functions that work like those defined per column. If you provide a getter method with the same name as a column, it will be used to access the value of that column. If you provide a name that does not match a column, this function will act as a virtual getter, that can fetch multiple other values

Optional hasTrigger

hasTrigger: boolean

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

Optional hooks

hooks: HooksDefineOptions<TInstance>

An object of hook function that are called before and after certain lifecycle events. The possible hooks are: beforeValidate, afterValidate, beforeBulkCreate, beforeBulkDestroy, beforeBulkUpdate, beforeCreate, beforeDestroy, beforeUpdate, afterCreate, afterDestroy, afterUpdate, afterBulkCreate, afterBulkDestory and afterBulkUpdate. See Hooks for more information about hook functions and their signatures. Each property can either be a function, or an array of functions.

Optional indexes

Indexes for the provided database table

Optional initialAutoIncrement

initialAutoIncrement: string

Set the initial AUTO_INCREMENT value for the table in MySQL.

Optional instanceMethods

instanceMethods: Object

Provide functions that are added to each instance (DAO). If you override methods provided by sequelize, you can access the original method using this.constructor.super_.prototype, e.g. this.constructor.super_.prototype.toJSON.apply(this, arguments)

Optional name

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

Optional omitNull

omitNull: boolean

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

Optional paranoid

paranoid: boolean

Calling destroy will not delete the model, but instead set a deletedAt timestamp if this is true. Needs timestamps=true to work. Default false.

Optional schema

schema: string

Optional scopes

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

Optional setterMethods

Provide setter functions that work like those defined per column. If you provide a setter method with the same name as a column, it will be used to update the value of that column. If you provide a name that does not match a column, this function will act as a virtual setter, that can act on and set other values, but will not be persisted

Optional tableName

tableName: string

Defaults to pluralized model name, unless freezeTableName is true, in which case it uses model name verbatim

Optional timestamps

timestamps: boolean

Adds createdAt and updatedAt timestamps to the model. Default true.

Optional underscored

underscored: boolean

Converts all camelCased columns to underscored if true. Default false.

Optional underscoredAll

underscoredAll: boolean

Converts camelCased model names to underscored tablenames if true. Default false.

Optional updatedAt

updatedAt: string | boolean

Override the name of the updatedAt column if a string is provided, or disable it if false. Timestamps must be true. Not affected by underscored setting.

Optional validate

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

Generated using TypeDoc