在我有同样的问题之前,当我了解设置功能的时候,解决了.
开门见山!
假设我们有两个对象:人与父亲
var Person = sequelize.define('Person', {
name: Sequelize.STRING
});
var Father = sequelize.define('Father', {
age: Sequelize.STRING,
//The magic start here
personId: {
type: Sequelize.INTEGER,
references: 'persons', // <<< Note, its table's name, not object name
referencesKey: 'id' // <<< Note, its a column name
}
});
Person.hasMany(Father); // Set one to many relationship
也许它帮助你
编辑:
你可以阅读这个更好的理解: