Mysql Query :
SELECT * FROM advisor_product_range WHERE 5 BETWEEN from_range AND to_range;
How to replicate the same in sequelize format
const AdvisorProductRangeDataGdp = await AdvisorProductRange.findAll({
attributes: ['office_id','yyyymmdd','product_type','from_range','to_range','amount_per_order'],
where: {
from_range: {
[dbOp.gte]: gdpCount
},
to_range: {
[dbOp.lte]: gdpCount
}
}
});
OUTPUT OF THIS QUERY IN MYSQL TERMS :
> SELECT `office_id`, `yyyymmdd`, `product_type`, `from_range`,
> `to_range`, `amount_per_order` FROM `advisor_product_range` AS
> `AdvisorProductRange` WHERE `AdvisorProductRange`.`from_range` <= 5 AND
> `AdvisorProductRange`.`to_range` >= 5;
Version : sequelize :5.8
CodePudding user response:
- Issue was found out its was related to the operator used in the query was switch in the incorrect way .
const AdvisorProductRangeDataGdp = await AdvisorProductRange.findAll({
attributes: ['office_id','yyyymmdd','product_type','from_range','to_range','amount_per_order'],
where: {
from_range: {
[dbOp.lte]: gdpCount
},
to_range: {
[dbOp.gte]: gdpCount
}
}
});