Slick: dynamic sortBy in a query with left join

两盒软妹~` 提交于 2019-12-01 10:39:48

.? is implemented using <> which prevents you from later accessing members. So you need to apply the sorting before you do the .?

    val data = for {
        (computer, company) <- Computer.where(_.name like filter) leftJoin
            Company on (_.companyId === _.id)
    } yield (computer, company) // <- no .?

    val sortedData = orderBy match {
        case 2 => data.sortBy(_._1.name) //Works ok, column from a primary table
        case 3 => data.sortBy(_._2.name) //Error "Cannot resolve symbol name", because table is optional
    }

    val optionalJoinData = sortedData.map{
      case (computer, company) => (computer, company.?)
    } // <- do .? last
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!