Is there a way in Slick 2.0 to create a method on a table class,that generates a SQL JOIN syntax rather than just a WHERE clause?
Using an example similar to the documentation:
class Suppliers(tag: Tag) extends Table[(Int, String)](tag, "SUPPLIER") {
...
def suppliedCoffees = coffees.filter(_.supplierId == id)
def * = (id, name)
}
class Coffees(tag: Tag) extends Table[(Int, Int, String)](tag, "COFFEES") {
...
def * = (id, supplierId, name)
}
I can create the suppliedCoffees
method and use it as such:
for {
s <- suppliers
c <- s.suppliedCoffees
} yield (s.name, c.name) ...
Nice and neat - easy to read, and the join criteria are nicely hidden. But this generates an SQL WHERE clause. How can I do something similar to the following, but using a method like suppliedCoffees
so that it's encapsulated in the class?
for {
(s, c) <- suppliers innerJoin coffees on (_.id === _.supplierId)
} yield (s, c) ...
Or better yet, how can I do an outer join? (but as a method like suppliedCoffees
)
for {
(s, c) <- suppliers leftJoin coffees on (_.id === _.supplierId)
} yield (s.name, c.name.?) ...
Thanks in advance.
Cheers, Rob.
p.s. Slick is awesome! It sure makes using an SQL database fun again :)