[英]how make a query in sequelize with a OR condition when that field is the foreignkey
i need some help with this query in sequelize, this query is working exactly how i want, but i don't have idea how can do that OR condition:我在续集中需要有关此查询的一些帮助,此查询完全按照我的意愿工作,但我不知道如何执行该 OR 条件:
select * from
core."Customers" c
inner join core."Townhouses" t
on t.id = c.townhouseid
inner join portal."TownhouseFreeFreights" tf
on tf.townhouseid = t.id
or tf.townhouseid is null
where c.id = 1
and tf."minValue" >= 0
the problem for me is that part: or tf.townhouseid is null我的问题是那部分:或者 tf.townhouseid 是 null
what i supposed to do here:我应该在这里做什么:
getFreightRules(){
return Customer.findAll({
include: [{
model: Townhouse,
require: true,
include:[{
model: TownhouseFreeFreights,
}]
}]
})
}
Something like this should work ( https://sequelize.org/master/manual/model-querying-basics.html#examples-with--code-op-and--code--and--code-op-or--code- )像这样的东西应该可以工作( https://sequelize.org/master/manual/model-querying-basics.html#examples-with--code-op-and--code--and--code-op-or- -代码- )
getFreightRules(){
return Customer.findAll({
include: [{
model: Townhouse,
require: true,
include:[{
model: TownhouseFreeFreights,
where: {
[Op.or]: [
{ tf.townhouseid: t.id },
{ tf.townhouseid: null }
]
}
}]
}]
})
}
alternatively或者
getFreightRules(){
return Customer.findAll({
include: [{
model: Townhouse,
require: true,
include:[{
model: TownhouseFreeFreights,
where: {
tf.townhouseid: {
[Op.or]: [t.id, null]
}
}
}]
}]
})
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.