findAll()
Use का उपयोग करें include()
. के साथ और sequelize.fn()
COUNT
. के लिए :
Location.findAll({
attributes: {
include: [[Sequelize.fn("COUNT", Sequelize.col("sensors.id")), "sensorCount"]]
},
include: [{
model: Sensor, attributes: []
}]
});
या, आपको एक group
add जोड़ने की आवश्यकता हो सकती है साथ ही:
Location.findAll({
attributes: {
include: [[Sequelize.fn("COUNT", Sequelize.col("sensors.id")), "sensorCount"]]
},
include: [{
model: Sensor, attributes: []
}],
group: ['Location.id']
})