使用
findAll()与
include()和
sequelize.fn()为
COUNT:
Location.findAll({ attributes: { include: [[Sequelize.fn("COUNT", Sequelize.col("sensors.id")), "sensorCount"]] }, include: [{ model: Sensor, attributes: [] }]});
或者,您可能还需要添加一个
group:
Location.findAll({ attributes: { include: [[Sequelize.fn("COUNT", Sequelize.col("sensors.id")), "sensorCount"]] }, include: [{ model: Sensor, attributes: [] }], group: ['Location.id']})
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)