static/v4/manual/tutorial/upgrade-to-v4.html
Manual»Tutorial
Sequelize v4 is the current release and it introduces some breaking changes. Majority of sequelize codebase has been refactored to use ES2015 features. The following guide lists some of the changes to upgrade from v3 to v4.
Full Changelog for v4 release.
To use new ES2015 features, Sequelize v4 requires at least Node v4 or above.
counterCache option for associations has been removed.dialect: 'mysql' an d Sequelize should be able to work with MariaDB server.Model.Instance and instance.Model are removed. To access the Model from an instance, simply use instance.constructor. The Instance class (Model.Instance) is now the Model itself.Sequelize.Promise instead of global bluebird Promise.v3, now you will need to call sequelize.close() to shutdown the pool.Removed support for old connection pooling configuration keys. Instead of
Removed support for pool: false. To use a single connection, set pool.max to 1.
Removed support for referencesKey, use a references object
references: {
key: '',
model: ''
}
Removed classMethods and instanceMethods options from sequelize.define. Sequelize models are now ES6 classes. You can set class / instance level methods like this
options.order now only accepts values with type of array or Sequelize method. Support for string values (ie {order: 'name DESC'}) has been deprecated.
With BelongsToMany relationships add/set/create setters now set through attributes by passing them as options.through (previously second argument was used as through attributes, now it's considered options with through being a sub option)
Raw options for where, order and group like where: { $raw: '..', order: [{ raw: '..' }], group: [{ raw: '..' }] } have been removed to prevent SQL injection attacks.
BIGINT now returned as string.DECIMAL and NEWDECIMAL types now returned as string.DataTypes.DATE now uses DATETIMEOFFSET instead of DATETIME2 sql datatype in case of MSSQL to record timezone. To migrate existing DATETIME2 columns into DATETIMEOFFSET, see #7201.DATEONLY now returns string in YYYY-MM-DD format rather than Date typeautocommit: true default, set this option explicitly to have transactions auto commit.REPEATABLE_READ transaction isolation. The isolation level now defaults to that of the database. Explicitly pass the required isolation level when initiating the transaction.Promise.all and other bluebird methods. Explicitly patch your bluebird instance to get CLS to work with bluebird methods.bind option would fallback to replacements if dialect didn't supported binding. This could be a breaking change for MySQL / MSSQL where now queries will actually use bind parameters instead of replacements fallback.Sequelize.Validator is now an independent copy of validator library.Model.validate instance method now runs validation hooks by default. Previously you needed to pass { hooks: true }. You can override this behavior by passing { hooks: false }.Model.validate instance method will be rejected when validation fails. It will fulfill when validation succeeds.Sequelize.Utils is not longer part of the public API, use it at your own risk.Hooks should return Promises now. Callbacks are deprecated.instance.get({ raw: true }), use instance.get({ plain: true })required inside include does not propagate up the include chain.