相关疑难解决方法(0)

使用Option进行左/右/外连接

在Slick示例中,有一些连接示例,其中一个结果列可以为空,因为在执行左,右或外连接时可能就是这种情况.例如:

val explicitLeftOuterJoin = for {
  (c, s) <- Coffees leftJoin Suppliers on (_.supID === _.id)
} yield (c.name, s.name.?)
Run Code Online (Sandbox Code Playgroud)

但是,如果我想返回整个映射对象呢?我的意思是:

val explicitLeftOuterJoin = for {
  (c, s) <- Coffees leftJoin Suppliers on (_.supID === _.id)
} yield (c, s.?)
Run Code Online (Sandbox Code Playgroud)

这似乎不起作用,因为它抱怨"找不到scala.slick.lifted.TypeMapper [供应商]类型的证据参数的隐含值".基本上我想要它返回一个元组列表(咖啡,选项[供应商])

为什么这不起作用,它的修复方法是什么?特别是,因为这很好:

val q = for {
  c <- Coffees
  s <- Suppliers
} yield (c, s)
Run Code Online (Sandbox Code Playgroud)

(我知道这是一个内部联接)

scala slick

17
推荐指数
2
解决办法
8688
查看次数

标签 统计

scala ×1

slick ×1