bullpen/backend/models/pitch.model.js

52 lines
1.2 KiB
JavaScript

const { Model } = require('sequelize');
module.exports = (sequelize, DataTypes) => {
class Pitch 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) {
Pitch.belongsTo(models.BullpenSession, {
foreignKey: 'bullpenSessionId',
as: 'bullpenSession'
});
Pitch.belongsTo(models.PitchType);
}
}
Pitch.init({
pitchTypeId: {
type: DataTypes.INTEGER,
allowNull: false,
references: { // User belongsTo PitchType 1:1
model: 'PitchTypes',
key: 'id'
}
},
bullpenSessionId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: 'BullpenSessions',
key: 'id'
}
},
pitchTime: {
type: DataTypes.DATE,
allowNull: false
},
aimedArea: {
type: DataTypes.INTEGER,
allowNull: false
},
hitArea: {
type: DataTypes.INTEGER,
allowNull: false
}
}, {
sequelize,
modelName: 'Pitch',
tableName: 'Pitches'
});
return Pitch;
};