我刚刚开始使用Slick,我做了一个简单的hello世界项目,发布帖子和评论。如何将Slick结果映射到不同的数据结构?
我想有以下数据结构:
Seq[(Post, Option[Seq[Comment]])]
然后,我可以遍历意见,像这样:
@for(p <- posts) {
@for(c <- posts.comments) {
@comment.title
}
}
这是我的查询:
def allWithComments = {
val q = for {
(p, c) <- Posts join Comments on (_.id === _.postsId)
} yield (p,c) // do here something fancy and map the result
db.run(q.result)
}
查询现在返回以下结构:
Seq[(models.Post, models.Comment)]
qResult从哪里来? –
'qResult'是'db.run(q.result)' – ryan
您可以发布包含解决方案的整个方法体吗? ,我有点困惑。 –