Using sequelize to check if the the db input property, which is array, has a given item. Have a Postgres database with data Events. Want to get one Event that will have any of these weekDays. Type of weekDays is ARRAY(integer).
Events.findOne({
where: {
weekDays: {
$contains: [2, 3],
},
},
});
Tried to do with $contains, $any, or $like $any but all the time got the same error message.
TypeError: values.map is not a function
Sincerely thanks
You are looking for overlapping values. Any value in you weekDays
array that matches any values in your passed in array.
As such, you can use the PG specific Sequelize.Op.overlap
operator:
See documentation here
Can then be used like
Events.findOne({
where: {
weekDays: {
[Sequelize.Op.overlap]: [2, 3],
},
},
});
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