Mise à jour de controleurs, models et routes

This commit is contained in:
Rampeur
2025-08-19 05:13:24 +02:00
parent f8d8ff2329
commit b1513dccdd
21 changed files with 905 additions and 113 deletions
+22
View File
@@ -42,6 +42,28 @@ const associate = () => {
DB.User.hasMany(DB.Follower, { as: "followers", foreignKey: "userId" });
DB.Follower.belongsTo(DB.User, { as: "follower", foreignKey: "followerId" });
DB.User.hasMany(DB.Follower, { as: "followerFollowers", foreignKey: "followerId" });
/*
// Relations
DB.User.belongsToMany(DB.User, { as: "followers", through: "Followers", foreignKey: "userId", timestamps: false });
DB.User.belongsToMany(DB.User, { as: "following", through: "Followers", foreignKey: "followerId", timestamps: false });
DB.User.hasMany(DB.Article, { foreignKey: "authorId", onDelete: "CASCADE" });
DB.Article.belongsTo(DB.User, { as: "author", foreignKey: "authorId" });
DB.User.hasMany(DB.Comment, { foreignKey: "authorId", onDelete: "CASCADE" });
DB.Comment.belongsTo(DB.User, { as: "author", foreignKey: "authorId" });
DB.Article.hasMany(DB.Comment, { foreignKey: "articleId", onDelete: "CASCADE" });
DB.Comment.belongsTo(DB.Article, { foreignKey: "articleId" });
DB.User.belongsToMany(DB.Article, { as: "favorites", through: "Favorites", timestamps: false });
DB.Article.belongsToMany(DB.User, { through: "Favorites", foreignKey: "articleId", timestamps: false });
DB.Article.belongsToMany(DB.Tag, { through: "TagLists", as: "tagLists", foreignKey: "articleId", timestamps: false, onDelete: "CASCADE" });
DB.Tag.belongsToMany(DB.Article, { through: "ArticleTags", uniqueKey: false, timestamps: false });
*/
};
module.exports = associate;