const config = require('../../config'); const providers = config.providers; const crypto = require('crypto'); const bcrypt = require('bcrypt'); const moment = require('moment'); module.exports = function (sequelize, DataTypes) { const presentations = sequelize.define( 'presentations', { id: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, primaryKey: true, }, name: { type: DataTypes.TEXT, }, license_expiration: { type: DataTypes.DATE, }, importHash: { type: DataTypes.STRING(255), allowNull: true, unique: true, }, }, { timestamps: true, paranoid: true, freezeTableName: true, }, ); presentations.associate = (db) => { db.presentations.belongsToMany(db.slides, { as: 'slides', foreignKey: { name: 'presentations_slidesId', }, constraints: false, through: 'presentationsSlidesSlides', }); db.presentations.belongsToMany(db.slides, { as: 'slides_filter', foreignKey: { name: 'presentations_slidesId', }, constraints: false, through: 'presentationsSlidesSlides', }); db.presentations.belongsToMany(db.analytics, { as: 'analytics', foreignKey: { name: 'presentations_analyticsId', }, constraints: false, through: 'presentationsAnalyticsAnalytics', }); db.presentations.belongsToMany(db.analytics, { as: 'analytics_filter', foreignKey: { name: 'presentations_analyticsId', }, constraints: false, through: 'presentationsAnalyticsAnalytics', }); /// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity //end loop db.presentations.belongsTo(db.users, { as: 'editor', foreignKey: { name: 'editorId', }, constraints: false, }); db.presentations.belongsTo(db.museums, { as: 'museums', foreignKey: { name: 'museumsId', }, constraints: false, }); db.presentations.belongsTo(db.users, { as: 'createdBy', }); db.presentations.belongsTo(db.users, { as: 'updatedBy', }); }; return presentations; };