Reputation: 1307
I am trying to join two tables using Slicks 3.0 monadic joins like this:
def getInfo(id: Int) = {
val innerJoin = for {
a <- tableA
b <- tableB if a.id === b.s_id
} yield b.name
println(innerJoin) // results in Rep(Bind)
innerJoin.map(println(_)) // results in Rep(Ref @1535257794)
}
Now I want to get the values from the join results. I tried a lot to get the values but it seems to be harder then I imagined. I always get some sort of Rep(Bind) back when I try to print the values (see comments above).
There is also this post which addresses the same problem. I tried the suggested solution which looks like this:
innerJoin.map(c => c).forEach(id =>
println(id)
)
Which doesn't even compile since forEach is not defined in that place. I don't really know how to proceed here an what to try next. Can someone help me out?
Thanks...
Upvotes: 0
Views: 3553
Reputation: 5699
val innerJoin
in your code is a slick query which can be extended / modified or turned into a DBIOAction
. An action is something that can be executed on a database which will eventually return your results:
val action = innerJoin.result
val results: Future[Seq[String]] = db.run(action)
// finally use map to access your result
results.map(s => s.map(name => ...) // s is of type Seq[String]
I assumed your for comprehension retuns a String
. Therefore the type of val results
is Future[Seq[String]]
.
Also have a look at http://slick.typesafe.com/doc/3.0.0/dbio.html#executing-database-i-o-actions
Upvotes: 4