When using Sequelize.js, the following code doesn\'t add any foreign key on tables.
var MainDashboard = sequelize.define(\'main_dashboard\', {
title: Sequ
For Sequelize 4 this has been updated to the following:
const Father = sequelize.define('Father', {
name: Sequelize.STRING
});
const Child = sequelize.define('Child', {
age: Sequelize.STRING,
fatherId: {
type: Sequelize.INTEGER,
references: {
model: 'fathers', // 'fathers' refers to table name
key: 'id', // 'id' refers to column name in fathers table
}
}
});
Father.hasMany(Child); // Set one to many relationship
Edit: You can read more on associations at https://sequelize.org/master/manual/assocs.html