I am creating where dynamically for my model. I want to use in for multiple values. I read documentation and online and found this:
Patient.findAll({
limit: limit,
offset: offset,
where: {
[Sequelize.Op.in]: patientIds
}
});
I want to build where something like this:
var filter = {
[Sequelize.Op.in]: patientIds,
is_active: filter.is_active
};
Patient.findAll({
limit: limit,
offset: offset,
where: filter
});
I also tried:
const op = Sequelize.Op;
const operatorsAliases = {
$in: op.in
};
and then:
var filter = {
operatorsAliases.$in: patientIds,
is_active: filter.is_active
};
But in both cases, it gives me error:
TypeError: s.replace is not a function
at Object.removeTicks (F:\Codes\medical_tourism\node_modules\sequelize\lib\utils.js:415:12)
at Object.quoteIdentifier (F:\Codes\medical_tourism\node_modules\sequelize\lib\dialects\mysql\query-generator.js:393:33)
at Object._getSafeKey (F:\Codes\medical_tourism\node_modules\sequelize\lib\dialects\abstract\query-generator.js:2298:33)
at Object._joinKeyValue (F:\Codes\medical_tourism\node_modules\sequelize\lib\dialects\abstract\query-generator.js:2274:16)
at Object._whereParseSingleValueObject (F:\Codes\medical_tourism\node_modules\sequelize\lib\dialects\abstract\query-generator.js:2332:23)
at Object.whereItemQuery (F:\Codes\medical_tourism\node_modules\sequelize\lib\dialects\abstract\query-generator.js:2090:19)
How to fix this?
You are missing the column on which you want to filter. Assuming 'id' is the column you want to filter, the code would look like:
Patient.findAll({
limit: limit,
offset: offset,
where: {
id: {
[Sequelize.Op.in]: patientIds
}
}
});
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