我的表中有两个外键,我正在尝试使用 OR 运算符来仅选择具有参数的表。
有没有可能的方法来做到这一点?类似的东西:
include: [
{
model: Segurado,
as: "segurado",
},
where: {
[Op.or]: {
{
model: Produtor,
as: "produtor1",
where: {
codigo: id_produtor,
},
},
{
model: Produtor,
as: "produtor2",
where: {
codigo: id_produtor,
},
},
}
}
],
最佳答案
尝试在 where 子句中调用模型。像那样:
{
where: {
[Op.or]: [
{ '$produtor1.documento$': documento_produtor },
{ '$produtor2.documento$': documento_produtor }
]
},
include: [
{
model: Produtor,
as: "produtor1"
},
{
model: Produtor,
as: "produtor2"
}
]
}
关于javascript - sequelize 中两个外键之间的 OR 运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61942717/