Question

When Sequelize saves an instance to a database (eg. MySQL) it automatically adds an "id" field at the end (auto-incremented also). I've read the articles and the documentation but I couldn't find any way to disable it.

Thank you.

Was it helpful?

Solution

It appears from the source that if you define an attribute as a 'primaryKey', the DAO interface will remove the default 'id' field in preference to your own primary key.

See line 1140 or thereabouts in dao-factory.js where:

var addDefaultAttributes = function() {
    var self              = this
      , defaultAttributes = {
        id: {
          type: DataTypes.INTEGER,
          allowNull: false,
          primaryKey: true,
          autoIncrement: true
        }
      }

    if (this.hasPrimaryKeys) {
      defaultAttributes = {}
    }

    ... etc. ...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top