Files
bowlingManager/backend/models/EventParticipant.js
T
2025-04-17 23:32:39 +09:00

60 lines
1.2 KiB
JavaScript

const { DataTypes } = require('sequelize');
const { sequelize } = require('../config/database');
const EventParticipant = sequelize.define('EventParticipant', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
},
eventId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: 'Events',
key: 'id'
}
},
memberId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: 'Members',
key: 'id'
}
},
status: {
type: DataTypes.ENUM('참가예정', '참가확정', '취소'),
allowNull: false,
defaultValue: '참가예정'
},
paymentStatus: {
type: DataTypes.ENUM('미납', '납부완료'),
allowNull: false,
defaultValue: '미납'
}
}, {
tableName: 'EventParticipants',
timestamps: true
});
// 관계 설정
EventParticipant.associate = (models) => {
EventParticipant.belongsTo(models.Event, {
foreignKey: 'eventId',
as: 'event'
});
EventParticipant.belongsTo(models.Member, {
foreignKey: 'memberId',
as: 'member'
});
EventParticipant.hasMany(models.EventScore, {
foreignKey: 'participantId',
as: 'scores'
});
};
module.exports = EventParticipant;