[英]ORM: Sequelize: many to many relationship query
How do I query in many to many relationships? 如何查询多对多关系? eg There are product, category, and product_category models.
例如,有产品,类别和product_category模型。 Below is an association by model:
以下是按型号关联:
// product
product.belongsToMany (models.category, {
through: 'product_category',
foreignKey: 'product_id'
});
// category
category.belongsToMany (models.product, {
through: 'product_category',
foreignKey: 'category_id'
});
// product_category
product_category.belongsTo (models.product, {
foreignKey: 'product_id'
});
product_category.belongsTo (models.category, {
foreignKey: 'category_id'
});
I would appreciate if you can tell me which model the findAll ()
should have at the beginning when querying. 如果您能在查询时告诉我
findAll ()
在开头应该具有哪种模型,我将不胜感激。
是的,如果你正在使用节点和续集它似乎是一个很好的契合,这是一个非常简单的提升,使GraphQL在你的解析器中运行和操纵你的续集模型...很高兴有graphiql游乐场用你的查询....容易豌豆
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.