Files
miriamgemeinde/models/event.js
2025-05-07 11:55:27 +02:00

81 lines
1.7 KiB
JavaScript

const { DataTypes } = require('sequelize');
module.exports = (sequelize) => {
const Event = sequelize.define('Event', {
uniqueId: {
type: DataTypes.STRING,
allowNull: true
},
eventTypeId: {
type: DataTypes.INTEGER,
allowNull: true
},
event_place_id: {
type: DataTypes.INTEGER,
allowNull: true
},
name: {
type: DataTypes.STRING,
allowNull: true
},
date: {
type: DataTypes.DATE,
allowNull: true
},
time: {
type: DataTypes.TIME,
allowNull: true
},
endTime: {
type: DataTypes.TIME,
allowNull: true
},
dayOfWeek: {
type: DataTypes.INTEGER,
allowNull: true
},
description: {
type: DataTypes.TEXT,
allowNull: true
},
alsoOnHomepage: {
type: DataTypes.INTEGER,
allowNull: false
},
relatedImage: {
type: DataTypes.STRING,
allowNull: true
}
}, {
tableName: 'events',
timestamps: true
});
Event.associate = function(models) {
Event.belongsTo(models.Institution, {
foreignKey: 'institution_id',
as: 'institution'
});
Event.belongsTo(models.EventPlace, {
foreignKey: 'event_place_id',
as: 'eventPlace'
});
Event.belongsTo(models.EventType, {
foreignKey: 'eventTypeId',
as: 'eventType'
});
Event.belongsToMany(models.ContactPerson, {
through: 'EventContactPerson',
foreignKey: 'event_id',
otherKey: 'contact_person_id',
as: 'contactPersons'
});
Event.belongsTo(models.Image, {
foreignKey: 'relatedImage',
as: 'relatedImageAssociation'
})
};
return Event;
};