我想用sequelizejs在多个表上添加or条件。我的问题是我不知道如何在多个表上使用or运算符($ or和Sequelize.or)。
假设我要实现以下sql-query:
select * from A as a, B as b, C as c where (A.b_id = b.id and b.x = 7) or (A.c_id = C.id and c.z = "test")
我只会像这样用续集来实现第一个条件:
A.findAll({
include: [{ model: B, where: { x: 7 } }]
})
而且只有这样的第二个条件:
A.findAll({
include: [{ model: C, where: { z: "test" } }]
})
但是,如何将两个查询合并为我想要的查询?
你可以做这样的事情
A.findAll({
include: [{model: B},{model: C}],
where: {
'$or':{
'$b.x$': 7,
'$c.z$': "test"
}
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句