module.exports = function (sequelize, DataTypes) { const Comment = sequelize.define('Comment', { id: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, primaryKey: true }, entityType: { field: 'type', type: DataTypes.STRING, allowNull: false }, entity: { type: DataTypes.VIRTUAL(DataTypes.UUID, ['conferenceId', 'speakerId', 'postId']), }, content: { type: DataTypes.STRING, allowNull: false }, user: { type: DataTypes.VIRTUAL(DataTypes.UUID, ['userId']), }, /*conference: { type: DataTypes.VIRTUAL(DataTypes.UUID, ['conferenceId']), },*/ post: { type: DataTypes.VIRTUAL(DataTypes.UUID, ['postId']), }, /*speaker: { type: DataTypes.VIRTUAL(DataTypes.UUID, ['speakerId']), },*/ }, { tableName: 'comments', freezeTableName: true, timestamps: true, }); Comment.associate = function (models) { Comment.User = Comment.belongsTo(models.User, { foreignKey: 'userId', constraints: false }); //Comment.Conference = Comment.belongsTo(models.Conference, { foreignKey: 'conferenceId', constraints: false }); Comment.Post = Comment.belongsTo(models.Post, { foreignKey: 'postId', constraints: false }); //Comment.Speaker = Comment.belongsTo(models.Speaker, { foreignKey: 'speakerId', constraints: false }); }; return Comment; };