Refactoring et ajout de routes Hero Wars
This commit is contained in:
@@ -1,69 +1,69 @@
|
||||
const DB = require('../mysql');
|
||||
|
||||
const associate = () => {
|
||||
/*
|
||||
DB.User.hasMany(DB.Article, {
|
||||
foreignKey: 'authorId',
|
||||
onDelete: "CASCADE"
|
||||
});
|
||||
|
||||
DB.Article.belongsTo(DB.User, {
|
||||
foreignKey: 'authorId',
|
||||
as: 'author',
|
||||
});
|
||||
*/
|
||||
DB.Article.belongsToMany(DB.Tag, { as: 'tagNameTags', through: DB.ArticleTag, foreignKey: "articleId", otherKey: "tagName" });
|
||||
DB.Article.belongsToMany(DB.Tag, { as: 'tagNameTagTagLists', through: DB.TagList, foreignKey: "articleId", otherKey: "tagName" });
|
||||
DB.Article.belongsToMany(DB.Tag, { as: 'articleTags', through: DB.TagList, foreignKey: "articleId", otherKey: "tagName" });
|
||||
DB.Article.belongsToMany(DB.User, { as: 'userIdUsers', through: DB.Favorite, foreignKey: "articleId", otherKey: "userId" });
|
||||
DB.Tag.belongsToMany(DB.Article, { as: 'articleIdArticles', through: DB.ArticleTag, foreignKey: "tagName", otherKey: "articleId" });
|
||||
DB.Category.belongsToMany(DB.Product, { as: 'productIdProducts', through: DB.ProductCategoryXref, foreignKey: "categoryId", otherKey: "productId" });
|
||||
DB.Product.belongsToMany(DB.Category, { as: 'productCategories', through: DB.ProductCategoryXref, foreignKey: "productId", otherKey: "categoryId" });
|
||||
DB.Product.belongsToMany(DB.Tag, { as: 'productTags', through: DB.ProductTagXref, foreignKey: "productId", otherKey: "tagName" });
|
||||
DB.Role.belongsToMany(DB.User, { as: 'userIdUserUserRoleXrefs', through: DB.UserRoleXref, foreignKey: "roleId", otherKey: "userId" });
|
||||
DB.Tag.belongsToMany(DB.Article, { as: 'articleIdArticleTagLists', through: DB.TagList, foreignKey: "tagName", otherKey: "articleId" });
|
||||
DB.User.belongsToMany(DB.Article, { as: 'articleIdArticleFavorites', through: DB.Favorite, foreignKey: "userId", otherKey: "articleId" });
|
||||
DB.Tag.belongsToMany(DB.Product, { as: 'productIdProductProductTagXrefs', through: DB.ProductTagXref, foreignKey: "tagName", otherKey: "productId" });
|
||||
DB.User.belongsToMany(DB.Article, { as: 'articleIdArticles', through: DB.Favorite, foreignKey: "userId", otherKey: "articleId" });
|
||||
DB.User.belongsToMany(DB.Role, { as: 'roleIdRoles', through: DB.UserRoleXref, foreignKey: "userId", otherKey: "roleId" });
|
||||
DB.User.belongsToMany(DB.User, { as: 'followerIdUsers', through: DB.Follower, foreignKey: "userId", otherKey: "followerId" });
|
||||
DB.User.belongsToMany(DB.User, { as: 'userIdUserFollowers', through: DB.Follower, foreignKey: "followerId", otherKey: "userId" });
|
||||
DB.ArticleTag.belongsTo(DB.Article, { as: "article", foreignKey: "articleId" });
|
||||
DB.Article.hasMany(DB.ArticleTag, { as: "articleTags", foreignKey: "articleId" });
|
||||
DB.Comment.belongsTo(DB.Article, { as: "article", foreignKey: "articleId" });
|
||||
DB.Article.hasMany(DB.Comment, { as: "comments", foreignKey: "articleId" });
|
||||
DB.Favorite.belongsTo(DB.Article, { as: "article", foreignKey: "articleId" });
|
||||
DB.Article.hasMany(DB.Favorite, { as: "favorites", foreignKey: "articleId" });
|
||||
DB.TagList.belongsTo(DB.Article, { as: "article", foreignKey: "articleId" });
|
||||
DB.Article.hasMany(DB.TagList, { as: "tagLists", foreignKey: "articleId" });
|
||||
DB.ArticleTag.belongsTo(DB.Tag, { as: "tagNameTag", foreignKey: "tagName" });
|
||||
DB.Tag.hasMany(DB.ArticleTag, { as: "articleTags", foreignKey: "tagName" });
|
||||
DB.TagList.belongsTo(DB.Tag, { as: "tagNameTag", foreignKey: "tagName" });
|
||||
DB.Tag.hasMany(DB.TagList, { as: "tagLists", foreignKey: "tagName" });
|
||||
DB.Article.belongsTo(DB.User, { as: "author", foreignKey: "authorId" });
|
||||
DB.User.hasMany(DB.Article, { as: "articles", foreignKey: "authorId" });
|
||||
DB.Comment.belongsTo(DB.User, { as: "author", foreignKey: "authorId" });
|
||||
DB.User.hasMany(DB.Comment, { as: "comments", foreignKey: "authorId" });
|
||||
DB.Favorite.belongsTo(DB.User, { as: "user", foreignKey: "userId" });
|
||||
DB.User.hasMany(DB.Favorite, { as: "favorites", foreignKey: "userId" });
|
||||
DB.Follower.belongsTo(DB.User, { as: "user", foreignKey: "userId" });
|
||||
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" });
|
||||
|
||||
DB.Comment.belongsTo(DB.Article, { as: "article", foreignKey: "articleId"});
|
||||
DB.Article.hasMany(DB.Comment, { as: "comments", foreignKey: "articleId"});
|
||||
DB.Favorite.belongsTo(DB.Article, { as: "article", foreignKey: "articleId"});
|
||||
DB.Article.hasMany(DB.Favorite, { as: "favorites", foreignKey: "articleId"});
|
||||
DB.TagList.belongsTo(DB.Article, { as: "article", foreignKey: "articleId"});
|
||||
DB.Article.hasMany(DB.TagList, { as: "tagLists", foreignKey: "articleId"});
|
||||
DB.Product.belongsTo(DB.Brand, { as: "brand", foreignKey: "brandId"});
|
||||
DB.Brand.hasMany(DB.Product, { as: "products", foreignKey: "brandId"});
|
||||
DB.ProductCategoryXref.belongsTo(DB.Category, { as: "category", foreignKey: "categoryId"});
|
||||
DB.Category.hasMany(DB.ProductCategoryXref, { as: "productCategoryXrefs", foreignKey: "categoryId"});
|
||||
DB.Product.belongsTo(DB.Packaging, { as: "packaging", foreignKey: "packagingId"});
|
||||
DB.Packaging.hasMany(DB.Product, { as: "products", foreignKey: "packagingId"});
|
||||
DB.ProductCategoryXref.belongsTo(DB.Product, { as: "product", foreignKey: "productId"});
|
||||
DB.Product.hasMany(DB.ProductCategoryXref, { as: "productCategoryXrefs", foreignKey: "productId"});
|
||||
DB.ProductTagXref.belongsTo(DB.Product, { as: "product", foreignKey: "productId"});
|
||||
DB.Product.hasMany(DB.ProductTagXref, { as: "productTagXrefs", foreignKey: "productId"});
|
||||
DB.UserRoleXref.belongsTo(DB.Role, { as: "role", foreignKey: "roleId"});
|
||||
DB.Role.hasMany(DB.UserRoleXref, { as: "userRoleXrefs", foreignKey: "roleId"});
|
||||
DB.ProductTagXref.belongsTo(DB.Tag, { as: "tagNameTag", foreignKey: "tagName"});
|
||||
DB.Tag.hasMany(DB.ProductTagXref, { as: "productTagXrefs", foreignKey: "tagName"});
|
||||
DB.TagList.belongsTo(DB.Tag, { as: "tagNameTag", foreignKey: "tagName"});
|
||||
DB.Tag.hasMany(DB.TagList, { as: "tagLists", foreignKey: "tagName"});
|
||||
DB.Article.belongsTo(DB.User, { as: "author", foreignKey: "authorId"});
|
||||
DB.User.hasMany(DB.Article, { as: "articles", foreignKey: "authorId"});
|
||||
DB.Comment.belongsTo(DB.User, { as: "author", foreignKey: "authorId"});
|
||||
DB.User.hasMany(DB.Comment, { as: "comments", foreignKey: "authorId"});
|
||||
DB.Favorite.belongsTo(DB.User, { as: "user", foreignKey: "userId"});
|
||||
DB.User.hasMany(DB.Favorite, { as: "favorites", foreignKey: "userId"});
|
||||
DB.Follower.belongsTo(DB.User, { as: "user", foreignKey: "userId"});
|
||||
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"});
|
||||
DB.Product.belongsTo(DB.User, { as: "owner", foreignKey: "ownerId"});
|
||||
DB.User.hasMany(DB.Product, { as: "products", foreignKey: "ownerId"});
|
||||
DB.UserRoleXref.belongsTo(DB.User, { as: "user", foreignKey: "userId"});
|
||||
DB.User.hasMany(DB.UserRoleXref, { as: "userRoleXrefs", foreignKey: "userId"});
|
||||
/*
|
||||
// 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 });
|
||||
// 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