I have learned that in Sequelize, we can add foreign keys to child model by two ways. One is to use hasOne
,belongsTo
,hasMany
and so on. Another way is to add references
to the props when we config the model like this:
trainer_id: {
type: DataTypes.INTEGER,
references: {
model: "trainers",
key: "id"
}
}
so What's the difference of them? I found it's simplier using refrences. I would appreciate it if you can give me some advice.
via laoqiren
No comments:
Post a Comment