当目标表也与第三个表关联时如何在连接中添加条件
假设我们有 表A, 表B, 表C,
a通过id与b关联 a 通过键与 c 关联 b 通过移动设备与 c 关联
,现在我在续集中查询,
A.findAll({
include: [
{
model: b
include: [
{
model: c
}
]
}
]
})
如何在 ON 中加入 B 和 C 时包含此条件(B.mobile = C.mobile 和 C.key = A.key)
Let's say we have
table A,
table B,
table C,
a is associated with b by id
a is associated with c by key
b is associated with c by mobile
now i am querying in sequelize
A.findAll({
include: [
{
model: b
include: [
{
model: c
}
]
}
]
})
now how can i include this condition on joining B and C in ON (B.mobile = C.mobile and C.key = A.key)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
include
选项的on
选项,如下所示:如果这样的
ON
在 MySQL 中不起作用,那么您可以尝试移动>key: Sequelize.col('A.key')
到主where
选项:You can use
on
option of theinclude
option like this:If such
ON
wouldn't work in MySQL then you can try to movekey: Sequelize.col('A.key')
to the mainwhere
option: