Files
pp-tcms/backend/models/comments.js
2026-02-23 12:26:07 +09:00

48 lines
1020 B
JavaScript

function defineComment(sequelize, DataTypes) {
const Comment = sequelize.define('Comment', {
commentableType: {
type: DataTypes.STRING,
allowNull: false,
},
commentableId: {
type: DataTypes.INTEGER,
allowNull: false,
},
userId: {
type: DataTypes.INTEGER,
allowNull: true,
},
content: {
type: DataTypes.TEXT,
allowNull: false,
},
});
Comment.associate = (models) => {
// Polymorphic associations
Comment.belongsTo(models.RunCase, {
foreignKey: 'commentableId',
constraints: false,
as: 'runCase',
});
Comment.belongsTo(models.Run, {
foreignKey: 'commentableId',
constraints: false,
as: 'run',
});
Comment.belongsTo(models.Case, {
foreignKey: 'commentableId',
constraints: false,
as: 'case',
});
Comment.belongsTo(models.User, {
foreignKey: 'userId',
onDelete: 'SET NULL',
});
};
return Comment;
}
export default defineComment;