Utilisation simultanée de mongodb et mysql

This commit is contained in:
Rampeur
2025-08-14 18:22:05 +02:00
parent 49b1a3f6b3
commit 8a011af73a
40 changed files with 3003 additions and 152 deletions
+13 -13
View File
@@ -1,29 +1,29 @@
const DB = require('../index');
const associate = () => {
/*
DB.User.hasMany(DB.Article, {
foreignKey: 'userId',
as: 'projects',
foreignKey: 'authorId',
onDelete: "CASCADE"
});
DB.Article.belongsTo(DB.User, {
foreignKey: 'userId',
as: 'user',
foreignKey: 'authorId',
as: 'author',
});
/*
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.belongsToMany(DB.User, { as: "followers", through: "follower", foreignKey: "userId", timestamps: false });
DB.User.belongsToMany(DB.User, { as: "following", through: "follower", 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.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 });
*/
DB.User.belongsToMany(DB.Article, { as: "favorites", through: "favorite", timestamps: false });
DB.Article.belongsToMany(DB.User, { through: "favorite", foreignKey: "articleId", timestamps: false });
DB.Article.belongsToMany(DB.Tag, { through: "tagList", as: "tagLists", foreignKey: "articleId", timestamps: false, onDelete: "CASCADE" });
DB.Tag.belongsToMany(DB.Article, { through: "articleTag", uniqueKey: false, timestamps: false });
};
module.exports = associate;