ndy*_*dyr 1 postgresql node.js sequelize.js hapijs
我有模型一,乙,和Ç。
A具有与B&C的hasMany关联(并且B&C具有回到A的belongs关联)
我想返回A的记录,其中B.b_column ='b'或C.c_column ='c'。
我当前的方法是尝试使用required:在哪里的false,但这仅返回A及其关联的所有记录(如果它们存在)。我还尝试在关联上使用split:true,但它似乎仍带回了比我想要的更多的记录。
var results = await A.all({
include: [
{
model: B, as: "Bs",
where: { b_column: "b"},
separate: true
},
{
model: C, as: "Cs",
where: {c_column: "c"},
separate: true
},
]
});
Run Code Online (Sandbox Code Playgroud)
您需要做的就是从根目录查询
干得好 :
A.all({ // <------ I think this should be A not B as per your question
include: [
{
model: B, as: "Bs"
},
{
model: C, as: "Cs"
},
],
where : {
$or : [
{ 'Bs.b_column' : "b" }, // <---- Might have to change table alias name
{ 'Cs.c_column' : "c" }
]
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
294 次 |
| 最近记录: |