0
votes

I am learning Sequelize and don't understand one moment. By default, the foreign key for a belongsTo relation will be generated from the target model name and the target primary key name. The default foreign key can be overwritten with the foreignKey option.

I have 2 tables (employee, department) with such associations:

db.employee.belongsTo(db.department, {foreignKey: 'emp_depID'});
db.department.hasMany(db.employee);

I've declared foreignKey like 'emp_depID' in the employee table, which references to department's id, but in my table I also have default column - department.id with Null value. How can I delete this default column? I don't need it.

1

1 Answers

0
votes
module.exports = function(connection, Sequelize){
  var Department = connection.define('Department', {
    name : Sequelize.STRING(50)
  });
  Department.removeAttribute('id');

  return Department;
};

before returning the model use removeAttribute method to remove any attribute