Reputation: 103
I am trying to perform a findall with sequelize, where i use $like.
Since the strings i need to evaluate with $like are from a form and change, in value or number, i send to sequelize an array.
Therefor, i would like to use $like for all values in my array.
But i couldn 't make it work yet.
var conditions =Array[String];
for (var element in req.query.HotelID) {
console.log(req.query.HotelID[element])
conditions.push(
req.query.HotelID[element]
);
}
console.log('in loop')
console.log(conditions)
db.hotelamadeus.findAll({
where: {$and:{ Name: req.query.hotel, HotelID :{[Op.like]: { [Op.any]: conditions}}}},
attributes: ['HotelID','Name'],
})
The strings are in req.query.HotelID.
The array conditions is created well.
I want to find the value in my table which map the conditions on the Name and HotelID fields.
So i tried to perform $like $any as i saw in many posts, but i am not sure sequelize can handle it, as it is not working.
Thanks for any help
Upvotes: 0
Views: 1890
Reputation: 878
Why don't you create a quick utility function that takes the array and column name and loops through the array and combines [Op.like] and [Op.or] for that? If you are using like then you'll need to append % in the desired places anyway so you have a little manipulation to do
Upvotes: 1