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)
Try this:
.joinLeft(countries).on(_._2.map(_.countryId) === _.id)
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