Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slick Join Left Option column

Tags:

scala

slick

I'm trying to join multiple Tables using Slick and i'm having difficulties joining Optional Values.

My migrated Model from Rails, the user had a separate Profile that could have an Address, which is Optional.

How do I query using Slick?

Current Code:

val query = for {
  (((((dbUser, dbUserProfile), dbAddress), dbCountry), dbUserLoginInfo), dbLoginInfo) <-
  users.filter(_.id === userID)
    .join(userProfiles).on(_.id === _.id)
    .joinLeft(addresses).on(_._2.addressId === _.id)
    .joinLeft(countries).on(_._2.get.countryId === _.id)
    .joinLeft(userLoginInfos).on(_._1._1._1.id === _.userId)
    .joinLeft(loginInfos).on(_._2.get.loginInfoId === _.id)
} yield (dbUser, dbUserProfile, dbAddress, dbCountry, dbLoginInfo)
like image 856
Driver Avatar asked Jun 04 '16 18:06

Driver


1 Answers

Try this:

.joinLeft(countries).on(_._2.map(_.countryId) === _.id)
like image 190
insan-e Avatar answered Oct 06 '22 00:10

insan-e