bullpen/backend/models/bullpenSession.model.js

45 lines
1015 B
JavaScript

'use strict';
const {
Model
} = require('sequelize');
module.exports = (sequelize, DataTypes) => {
class BullpenSession 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) {
BullpenSession.hasMany(models.Pitch, {
foreignKey: 'bullpenSessionId',
as: 'pitches',
});
BullpenSession.belongsTo(models.User, {
as: "pitcher"
});
}
}
BullpenSession.init({
pitcherId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: 'User',
key: 'id'
}
},
startedAt: {
type: DataTypes.DATE,
allowNull: false,
},
finishedAt: {
type: DataTypes.DATE,
allowNull: false,
}
}, {
sequelize,
modelName: 'BullpenSession',
tableName: 'BullpenSessions'
});
return BullpenSession;
};