bullpen/backend/models/position.model.js

39 lines
1.0 KiB
JavaScript

const { Model } = require('sequelize');
module.exports = (sequelize, DataTypes) => {
class Position 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) {
Position.belongsToMany(models.Player, {
through: "PlayerPositions",
foreignKey: 'positionId',
otherKey: 'playerId',
as: 'players',
});
}
}
Position.init({
name: {
type: DataTypes.STRING,
allowNull: false,
unique: true
},
abbreviation: {
type: DataTypes.STRING,
allowNull: false
},
description: {
type: DataTypes.STRING,
allowNull: false
}
}, {
sequelize,
modelName: 'Position',
tableName: 'Positions'
});
return Position;
};