sequelize model:create --name comments --attributes news_id:integer,name:string,comment:string
reference of association.
static associate(models) {
// define association here
this.belongsTo(models.news, {
foreignKey: `news_id`
})
}
static associate(models) {
// define association here
this.hasMany(models.comments, {
foreignKey : "news_id"
})
}
news_id: {
type: Sequelize.INTEGER,
allowNull: false,
onDelete: 'CASCADE', // untuk kasih konfig apabila data member dihapus maka data loan dihapus
references: {
model: "news",
key: 'id'
}
}
npm run db:migrate
Create class CommentService and create method store for function create data comment for news id.

Crete class controller for handle rest expressjs.