'How to Filter rows in table with JSON column values - Sequalize, mySql
i need to filter the table by using order.id which is nested 2 levels deeper inside the item column can we filter them in sequalize
i don't know how to filter them
code:
item: datatype.jsonb
item:[{
Order:[
{
id: 01,
name: xxxx,
},
{
id:02,
name:yyyy,
}
]
}]
Solution 1:[1]
model.findAll({
where: {
'$item.Order.id$': 2;
},
include: [{ model: item, include: [{ model: Order}] }]
})
You can filter them using outer where condition if you want to filter whole data setup according to that where condition, otherwise you can add where condition inside include object like this
model.findAll({
include: [{ model: item, include: [{ model: Order, where: { id: 2 } }] }]
})
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Urvik Patel |
