feat: comment to test run's case (#390)
This commit is contained in:
47
backend/models/comments.js
Normal file
47
backend/models/comments.js
Normal 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;
|
||||
@@ -23,6 +23,10 @@ function defineRunCase(sequelize, DataTypes) {
|
||||
foreignKey: 'caseId',
|
||||
onDelete: 'CASCADE',
|
||||
});
|
||||
RunCase.hasMany(models.Comment, {
|
||||
foreignKey: 'commentableId',
|
||||
onDelete: 'CASCADE',
|
||||
});
|
||||
};
|
||||
|
||||
return RunCase;
|
||||
|
||||
Reference in New Issue
Block a user