0

I have a case class being instantiated based on some DB operations:

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))

The problem is that I would not like to specify any bookiesOdds in this query (they are filled in some other query). Instead I would like to create a tuple tupledJoin containing an empty sequence of Seq[BookiesOddsRow] to create my case class' object. Is there any way of mixing that in a for-comprehension loop? I suppose I need something like that:

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)

Is this possible? How to implement it correctly?

Best Regards

Gandalf
  • 155
  • 1
  • 12
  • Your last snippet seems to be doing exactly what you describer. What's the problem? – Dima Jul 08 '16 at 11:50
  • I got the error `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.` – Gandalf Jul 08 '16 at 13:49
  • I don't see anything to do with slick in your snippet. Your question must have to do with some specifics of slick, but you haven't posted nearly enough details to identify that problem. I can tell you that there is absolutely nothing wrong with the `for-comprehension` snippet you posted. – Dima Jul 08 '16 at 13:54
  • Strange thing is that when I use `yield (f, b1, b2, 5L)` with the last static value - it works. – Gandalf Jul 09 '16 at 11:55

1 Answers1

1

I think you can only use DB actions in the for comprehension. You could try this (not tested):

val tupledJoin = for {
    f <- Fights
    b1 <- Boxers if f.firstBoxerId === b1.id
    b2 <- Boxers if f.secondBoxerId === b2.id
    bookiesOdds <- DBIOAction.successful(Seq())
} yield (f, b1, b2, bookiesOdds)
devkat
  • 1,624
  • 14
  • 15