Skip to content

Upgrade from 2.0 to 3.0

Sushant edited this page Jun 25, 2016 · 2 revisions

Introduction

Sequelize 3.0 was a major change in library. Most of changes introduced are breaking changes. Here is list of major changes that you should care about

Methods

  • findById / findByPrimary added. They accept single argument which can be used to find a record based on a primary key value. They also accept options as second argument.
  • findOne / findAll / findAndCount / findOrCreate they all now accept single options argument.
  • create / bulkCreate / save no longer takes an array of fields as its second argument, use options.fields instead.
  • (REMOVED)findAllJoin
  • findOne will accept options argument and will no longer take string / integer / binary as argument
  • increment / decrement no longer take number in second argument

Associations

  • belongsToMany now required through option. This mean use of junction table with belongsToMany is now required. For other cases you can use hasMany for 1:N relations
  • belongsToMany accessor methods will be based on as parameter or target model name.
  • N:M relation can't be represented by 2x hasMany, you should use belongsToMany now.

API Surface

  • Removed
    • Query Chainer
    • Migrations, use sequelize/umzug and sequelize/cli
    • instance.isDirty, use instance.changed()
    • instance.values , use instance.get()
    • instance.primaryKeyValues
    • instance.identifiers, use instance.where()
    • instance.isDeleted, now simply check timestamp get('deletedAt')
    • where: "raw query", use where: ["raw query", [replacements]]
  • Changes
    • sequelize.query now only takes sql and options as arguments, the second and fourth argument callee and replacements has been removed and should be set via options.instance / options.model and options.replacements instead.
    • (DEPRECATED) referecesKey property in Model attributes, use references object: {type: Sequelize.INTEGER, references: { model: SomeModel, key: 'some_key' }}

Home

Getting Started

  • Installation
  • Basic Setup
  • With Express.JS
  • Sequelize CLI
  • Relationships
    • 1 : 1
    • 1 : n
    • n : m
    • Polymorph
  • Hooks
  • Pooling
  • Debugging
  • Migrations

How To

Resources

Upgrade Guides

Help

Clone this wiki locally