Azeli
Azeli

Reputation: 748

Scala Slick filter and join

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)

Upvotes: 6

Views: 9699

Answers (1)

ulas
ulas

Reputation: 473

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.

Upvotes: 8

Related Questions