Retrieve comment pfp & name

This commit is contained in:
Rykkel
2024-08-12 18:33:28 +08:00
parent fd0bd85219
commit d89a58f809
3 changed files with 18 additions and 5 deletions

View File

@@ -22,10 +22,12 @@ module.exports = (sequelize, DataTypes) => {
Comment.associate = (models) => {
Comment.belongsTo(models.User, {
foreignKey: 'userId',
as: "user",
onDelete: 'CASCADE',
});
Comment.belongsTo(models.Post, {
foreignKey: 'postId',
as: "post",
onDelete: 'CASCADE',
});
Comment.hasMany(models.Comment, {

View File

@@ -309,6 +309,7 @@ router.get("/:id/getComments", async (req, res) => {
include: [
{
model: User,
as: "user",
attributes: ["id", "firstName", "lastName"], // Specify the attributes you need
},
],