i want to get result: group + count of messages which belong to the current group for example:
webdevelopment - 34 messages
How can I achieve the same result without performing _.each
how i can to get the result one Query I used MySql, my code something like this
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.');
});
});
});
my module somethink like this
module messages
module.exports = {
attributes: {
id:{
type: 'integer',
primaryKey: true,
autoIncrement: true
},
groupId:{
type:'int'
}
}
};
module Group
module.exports = {
attributes: {
id:{
type: 'integer',
primaryKey: true,
autoIncrement: true
},
groupName:{
type:'string'
}
}
};