【问题标题】:Slick Join Left Option columnSlick Join Left Option 列
【发布时间】:2016-10-04 15:55:53
【问题描述】:

我正在尝试使用 Slick 加入多个表格,但在加入可选值时遇到了困难。

我从 Rails 迁移的模型,用户有一个单独的配置文件,可以有一个地址,这是可选的。

如何使用 Slick 进行查询?

当前代码:

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)

【问题讨论】:

    标签: scala slick


    【解决方案1】:

    试试这个:

    .joinLeft(countries).on(_._2.map(_.countryId) === _.id)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-14
      • 2020-03-30
      • 2022-09-29
      • 2018-03-24
      • 2010-09-29
      • 1970-01-01
      相关资源
      最近更新 更多