feat: comment to test run's case (#390)

This commit is contained in:
kimatata
2026-02-23 12:26:07 +09:00
committed by GitHub
parent 1f4ac0ae7b
commit a9674c81ab
27 changed files with 1045 additions and 40 deletions

View File

@@ -0,0 +1,47 @@
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;

View File

@@ -23,6 +23,10 @@ function defineRunCase(sequelize, DataTypes) {
foreignKey: 'caseId',
onDelete: 'CASCADE',
});
RunCase.hasMany(models.Comment, {
foreignKey: 'commentableId',
onDelete: 'CASCADE',
});
};
return RunCase;