1
Good evening dear friends,
I’m developing an API with Node.JS / Express / Sequelize and I need some help. As it is the first time that I use relational databases with Node, I don’t know exactly how to make a relationship between the tables Players and Teams. The logic is as follows:
- A player belongs to only one team;
- A team may have one or more players;
The models are as follows::
class Player extends Model {
static init(sequelize) {
super.init({
name: type: DataTypes.STRING,
nickname: type: DataTypes.STRING,
position_id: DataTypes.INTEGER,
team_id: DataTypes.INTEGER,
}, {
sequelize
});
}
static associate(models) {
// ???????????????????????????????????????????
}
}
class Team extends Model {
static init(sequelize) {
super.init({
name: type: DataTypes.STRING,
}, {
sequelize
});
}
static associate(models) {
// ???????????????????????????????????????????
}
}
What is the right way to implement associations using Foreign Keys?
valeu brother! helped my ass out here
– Roberto Oliveira