Created Tag, PostTag model & associations

This commit is contained in:
Rykkel
2024-08-11 19:32:05 +08:00
parent b3ee7b4859
commit 82fe2c4940
3 changed files with 69 additions and 3 deletions

View File

@@ -21,11 +21,19 @@ module.exports = (sequelize, DataTypes) => {
userId: {
type: DataTypes.UUID,
allowNull: false,
},
},
}, {
tableName: 'posts',
timestamps: true,
});
Post.associate = (models) => {
Post.belongsToMany(models.Tag, {
through: models.PostTag,
foreignKey: 'postId',
otherKey: 'tagId',
});
};
return Post;
}
};