Answer the question
In order to leave comments, you need to log in
Why is Sequelize COUNT not included in the selection?
Hello!
I have a strange case. I make a selection in the database using Sequelize:
const result = await Orders.findAll({
attributes: ['college', [Sequelize.fn('COUNT', Sequelize.col('id')), 'count_col']],
where: {
category: 7,
status: 30,
downloaded: 0
},
group: ['college']
})
SELECT `college`, COUNT(`id`) AS `count_col` FROM `Orders` AS `Orders` WHERE `Orders`.`category` = 7 AND `Orders`.`status` = 30 AND `Orders`.`downloaded` = 0 GROUP BY `college`;
result.map(current => console.log(current.count_col))
result.map(current => console.log(current))
Orders {
dataValues: { college: 12, count_col: 11 }, // ЗДЕСЬ count_col ЕСТЬ!
_previousDataValues: { college: 12, count_col: 11 },
_changed: {},
_modelOptions: {
...
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question