Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to change the default "id" column that is created automatically?

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.

like image 607
sotirelisc Avatar asked Dec 15 '13 22:12

sotirelisc


1 Answers

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. ...
like image 165
Rob Raisch Avatar answered Nov 13 '22 14:11

Rob Raisch