I want to add an or condition over multiple tables with sequelizejs. My problem is that I don't know how to use the or operators ($or and Sequelize.or) over more than one table.
Let's say I want to implement the following 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")
I would implement only the first condition with sequelize like this:
A.findAll({
include: [{ model: B, where: { x: 7 } }]
})
And only the second condition like this:
A.findAll({
include: [{ model: C, where: { z: "test" } }]
})
But how do I combine both queries into the one I want?
you can do something like this
A.findAll({
include: [{model: B},{model: C}],
where: {
'$or':{
'$b.x$': 7,
'$c.z$': "test"
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With