我的加入看起来像这样:
def byIdWithImage = for {
userId <- Parameters[Long]
(user, image) <- Users leftJoin RemoteImages on (_.imageId === _.id) if user.id === userId
} yield (user, image)
但当 user.imageId 为 null 时,slick 在运行时失败
[SlickException:读取列 RemoteImage.url 的 NULL 值]
将产量更改为
} yield (user, image.?)
给我一个编译时异常,它仅适用于单个列
找不到 scala.slick.lifted.TypeMapper[image.type] 类型的证据参数的隐式值
是否有不同的方法来完成我在这里想做的事情? (在单个查询中)
使用下面的代码,您可以将其写成:产量(用户,图像。也许)
case class RemoteImage(id: Long, url: URL)
class RemoteImages extends Table[RemoteImage]("RemoteImage") {
def id = column[Long]("id", O.PrimaryKey, O.AutoInc)
def url = column[URL]("url", O.NotNull)
def * = id.? ~ url <> (RemoteImage.apply _, RemoteImage.unapply _)
def maybe = id.? ~ url.? <> (applyMaybe,unapplyBlank)
val unapplyBlank = (c:Option[RemoteImage])=>None
val applyMaybe = (t: (Option[Long],Option[URL])) => t match {
case (Some(id),Some(url)) => Some(RemoteImage(Some(id),url))
case _ => None
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)