【发布时间】:2016-11-10 18:23:29
【问题描述】:
我有一个基于一些数据库操作的案例类:
case class FullFight(fight: FightsRow, firstBoxer: BoxersRow,
secondBoxer: BoxersRow, bookiesOdds: Seq[BookiesOddsRow])
val tupledJoin = for {
f <- Fights
b1 <- Boxers if f.firstBoxerId === b1.id
b2 <- Boxers if f.secondBoxerId === b2.id
} yield (f, b1, b2)
db.run(tupledJoin.result).map(_.map(FullFight.tupled))
问题是我不想在这个查询中指定任何 bookiesOdds(它们被填写在其他查询中)。相反,我想创建一个包含 Seq[BookiesOddsRow] 空序列的元组 tupledJoin 来创建我的案例类的对象。有没有办法在一个理解循环中混合它?我想我需要这样的东西:
val seq: Seq[BookiesOddsRow] = Nil
val tupledJoin = for {
f <- Fights
b1 <- Boxers if f.firstBoxerId === b1.id
b2 <- Boxers if f.secondBoxerId === b2.id
} yield (f, b1, b2, seq)
这可能吗?如何正确实现?
最好的问候
【问题讨论】:
-
您的最后一个 sn-p 似乎完全按照您的描述进行。有什么问题?
-
我收到了错误
not enough arguments for method map: (implicit shape: slick.lifted.Shape[_ <: slick.lifted.FlatShapeLevel, (models.Tables.Fights, models.Tables.Boxers, models.Tables.Boxers, Seq[models.Tables.BookiesOddsRow]), T, G])slick.lifted.Query[G,T,Seq]. Unspecified value parameter shape. -
我在您的 sn-p 中看不到与 slick 有任何关系。您的问题一定与 slick 的一些细节有关,但您没有发布几乎足够的详细信息来确定该问题。我可以告诉你,你发的
for-comprehensionsn-p 绝对没有问题。 -
奇怪的是,当我将
yield (f, b1, b2, 5L)与最后一个静态值一起使用时 - 它可以工作。
标签: scala functional-programming yield for-comprehension