【发布时间】:2022-01-18 08:04:49
【问题描述】:
我可能错误地用了我的帖子标题。 我有表 A,其 PK:“id”是表 B 中复合主的 FK。表 A 还保存表 C 中记录的复合 PK id 作为 FK。我需要帮助编写一个 Sequelize 查询,以查找与表 B 中的许多记录匹配的表 A ID,并具有指向另一组要匹配的许多记录的表 C FK。
到目前为止,我有:
TableA.findAll({
attributes: ["id"],
where: {
include: [
{
model: "TableB",
where: {
TableA_id: {$col: "TableA.id"} // Need all records that share this
}
},
{
model: "TableC",
where: {
TableC_value: [4, 5, 6], //I need the record where these all share the same key
TableC_PK: {$col: TableA.TableC_FK}
}
}
]
}
})
我还没有对此进行测试,但我也不知道我是否走在正确的轨道上。
【问题讨论】:
标签: mysql node.js join sequelize.js