score:3

Accepted answer

you need to group your result by post, author and receiver and the map to aggregate the comments by just counting them.

val posts = (for {
  p <- posts.query if p.receiver === userid
  comment <- comments.query if comments.postid === p.id
  author <- users.query if p.author === author.id
  receiver <- users.query if p.receiver === receiver.id
} yield (p, comment, author, receiver)) //so far thats your current query
  .groupby({ //group by post, author and receiver
      case (post, comment, author, receiver) =>
          (post, author, receiver)
  })
  .map({ //aggregate your comments (second argument in tuple) and count them
      case ((post, author, receiver), list) => { 
          (post, author, receiver, list.map(_._2).count))
      }
  })

on mobile currently so this probably won't compile, but you should get the idea.


Related Query

More Query from same tag