Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala Slick filter and join

Tags:

scala

slick

When performing filter-joins in Slick, what is the difference under the hood between the following two methods?

val query = for {
 c <- coffees if c.price < 9.0
 s <- c.supplier -- assuming there is a foreign key
} yield (c.name, s.name)

and

val query = for {
 (cof, sup) <- coffees.filter(_.price < 9.0) join supplier on(_.supId === _.id)
} yield (cof.name, sup.name)
like image 399
Azeli Avatar asked Feb 10 '16 22:02

Azeli


1 Answers

The first one is an implicit join and the second is an explicit join. Slick generates a WHERE clause for the former like: WHERE c.price < 9 AND c.supId = s.id. However the latter generates a JOIN like JOIN supplier s ON c.supId = s.id. You can have a look at these examples.

like image 199
ulas Avatar answered Nov 04 '22 11:11

ulas