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)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With