Mise à jour de controleurs, models et routes
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user