Ajout de la base de données MySQL

This commit is contained in:
Rampeur
2025-08-13 21:51:07 +02:00
parent be44e4fdf0
commit 49b1a3f6b3
35 changed files with 1579 additions and 37 deletions
+29
View File
@@ -0,0 +1,29 @@
const DB = require('../index');
const associate = () => {
DB.User.hasMany(DB.Article, {
foreignKey: 'userId',
as: 'projects',
});
DB.Article.belongsTo(DB.User, {
foreignKey: 'userId',
as: 'user',
});
/*
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.omment, { 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;