Scala Multiple Slides Slick 3.1

I am trying to make several connections in Slick 3.1.1. The result that I would like to achieve is as follows:

SELECT * FROM customer LEFT JOIN customer_address ON customer.id = customer_address.customer_id LEFT JOIN address ON customer_address.address_id = address.id 

I tried the following:

 val query = for { c <- Customer ca <- CustomerAddress if ca.customerId === c.id a <- Address if a.id === ca.addressId } yield (c, a) 

The problem is that if the client does not have an address that is not displayed, this makes sense.

Then I tried this:

  val query2 = for { (c, ca, a) <- (Customer joinLeft CustomerAddress on (_.id === _.customerId)) joinLeft Address on (_._2.addressId === _.id) } yield (c, a) 

The problem here is that I get the error _._2.addressId because _._2 is a Rep object.

Exact error:

 Error:(21, 110) value addressId is not a member of slick.lifted.Rep[Option[Models.Tables.CustomerAddress]] (c, ca, a) <- (Customer joinLeft CustomerAddress on (_.id === _.customerId)) joinLeft Address on (_._2.addressId === _.id) 

Automatically generated Slick Tables class: http://pastebin.com/e4M3cGU8

How to get the results I want using Slick?

+6
source share
2 answers

What you need to do is also display the results.

 val query2 = for { ((c, ca), a) <- (Customer joinLeft CustomerAddress on (_.id === _.customerId)) joinLeft Address on (_._2.map(_.addressId) === _.id) } yield (c, a) 
+3
source

That should work. // ((c, ca), a) instead of (c, ca, a)

 val query2 = for { ((c, ca), a) <- (Customer joinLeft CustomerAddress on (_.id === _.customerId)) joinLeft Address on (_._2.addressId === _.id) } yield (c, a) 
+1
source

All Articles