【发布时间】:2015-02-17 23:23:15
【问题描述】:
我想得到结果:组+属于当前组的消息数 例如:
webdevelopment - 34 messages
如何在不执行 _.each 的情况下获得相同的结果
我怎样才能得到一个查询的结果 我用过MySql, 我的代码是这样的
Group.find().exec(function (err, groups) {
if (err)
return next(err);
_.each(groups, function (grouper) {
Messages.count({
groupId : grouper.groupId,
}).exec(function (err, found) {
console.log(grouper.groupName + ' - ' + found + ' messages.');
});
});
});
我的模块有点像这样
模块消息
module.exports = {
attributes: {
id:{
type: 'integer',
primaryKey: true,
autoIncrement: true
},
groupId:{
type:'int'
}
}
};
模块组
module.exports = {
attributes: {
id:{
type: 'integer',
primaryKey: true,
autoIncrement: true
},
groupName:{
type:'string'
}
}
};
【问题讨论】: