const { Model } = require('sequelize'); module.exports = (sequelize, DataTypes) => { class Team extends Model { /** * Helper method for defining associations. * This method is not a part of Sequelize lifecycle. * The `models/index` file will call this method automatically. */ static associate(models) { Team.belongsToMany(models.Player, { through: "PlayerTeams", foreignKey: 'teamId', otherKey: 'playerId', as: 'players', }); } } Team.init({ name: { type: DataTypes.STRING, allowNull: false, unique: true }, description: { type: DataTypes.STRING, allowNull: false } }, { sequelize, modelName: 'Team', tableName: 'Teams' }); return Team; };