我正在尝试创建WHERE条件,该条件在“ person.name”列或“ person-> associates-> friends.username”列之间包含OR关系。将where条件嵌入到include(朋友模型)中会创建AND关系,这不是我所需要的。
为简单起见,举一个例子:
Person.findAll({
where: {
$or: [
{
name: 'John'
},
{
'$associates.friends.userName$': 'John'
}
]
},
include: [
{
model: Associates,
as: 'associates',
include: [
model: Friends,
as: 'friends'
]
}
]
})
这样做会产生以下错误: ““'where子句'中的未知列'associates-> friends.userName'”
联接将列重命名为“ associates.friends.username”,但是嵌套列语法似乎想将第一个句点重命名为“”。到“->”。对此有任何支持吗?
编辑:添加一张使我最接近我需要的图片。
当前版本5.21.2。
答案 0 :(得分:0)
相信我在这里找到了问题的原因。
Person.findAll({
where: {
$or: [
{
name: 'John'
},
{
'$associates.friends.userName$': 'John'
}
]
},
include: [
{
model: Associates,
as: 'associates',
include: [
model: Friends,
as: 'friends'
]
}
]
})
``
This code **does** work correctly. in my example I also have a *"limit"* property included and it is the inclusion of this *"limit"* that changes the query and causes the error. the above query parameters on their own seem to do the trick!