how to add search filter inside sequelize include in node/javascript
You get this result because the query's where statement is executed separately as a subquery. So, if you want to generate a where clause like this WHERE Collection.customer = 'blabla' AND Item.itemId = 1 , you should do the following:
model.Collection.findAll({
where: {
customer: customerParam,
'$items.itemId$': itemParam
},
include: [{
model: models.Item,
as: 'items'
}]
})
or you can do something like this->
let whereStatement = <any>{
communityId: params.communityId, status: constants.REQUEST_STATUS.pending,
[Op.or]: [
{
'$users.name$': {
[Op.iLike]: '%' + params.searchKey + '%'
}
},
{
'$users.userName$': {
[Op.iLike]: '%' + params.searchKey + '%'
}
},
{
'$users.email$': {
[Op.iLike]: '%' + params.searchKey + '%'
}
},
{
'$collaborators.name$': {
[Op.iLike]: '%' + params.searchKey + '%'
}
},
{
'$collaborators.userName$': {
[Op.iLike]: '%' + params.searchKey + '%'
}
},
{
'$collaborators.email$': {
[Op.iLike]: '%' + params.searchKey + '%'
}
}
]
}
Post a Comment