Ajout de la base de données MySQL
This commit is contained in:
@@ -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;
|
||||
Reference in New Issue
Block a user