Reputation: 1252
I want to write a little bit complex where
in sequelize using 3 or condition.
SQL where
example:
where
(c1 = 'a' or c2 = 'b' or c3 = 'c' or c4 = 'd')
and (c5 = 'e' or c6 = 'f' or c7 = 'g' or c8 = 'h')
and (c9 = 'i' or c10 = 'j')
In sequlelize I wrote something like this:
where: {
$and: {
$or: [{ c1: 'a' }, { c2: 'b' }, { c3: 'c' }, { c4: 'd' }]
},
$or: [{ c5: 'e' }, { c6: 'f' }, { c7: 'g' }, { c8: 'h' }]
}
but how can I add this object: $or: [{ c9: 'i' }, { c10: 'j' }]
?
P.S. Don't worry in project I use Op
.
Upvotes: 1
Views: 64
Reputation: 386868
You need an outer $and
property with the terms of the inner parts.
where: {
$and: [
{
$or: [
{ c1: 'a' }, { c2: 'b' }, { c3: 'c' }, { c4: 'd' }
]
},
{
$or: [
{ c5: 'e' }, { c6: 'f' }, { c7: 'g' }, { c8: 'h' }
]
},
{
$or: [
{ c9: 'i' }, { c10: 'j' }
]
}
]
}
Upvotes: 2