gpt4 book ai didi

scala - 为什么光滑的投影不起作用

转载 作者:行者123 更新时间:2023-12-01 08:09:48 25 4
gpt4 key购买 nike

出于某种原因,就我而言,即使是简单的 Slick 表声明也不起作用。我正在使用 slick 2.10 (1.0.0),这是 maven 中央存储库中的最新版本。

case class DeviceType(id: Option[Int] = None, name: String, version: String)

object DeviceTypes extends Table[DeviceType]("device_types") {

def id = column[Int]("id", O.PrimaryKey, O.AutoInc)
def name = column[String]("name", O.NotNull)
def version = column[String]("version")

def * = id.? ~ name ~ version <> (DeviceType, DeviceType.unapply _)


def delete(device_type: DeviceType): Unit = {
database withSession { implicit session : Session =>
val dt_query = for(dt <- DeviceTypes if dt.id == device_type.id.get) yield dt
//Query(DeviceTypes).filter(_.id == device_type.id.get)
dt_query.delete
}
}
}

[warn] /home/salil/Scala/sd_ventures/app/models/DeviceType.scala:38: scala.slick.lifted.Column[Int] and Int are unrelated: they will most likely never compare equal
[warn] val dt_query = for(dt <- DeviceTypes if dt.id == device_type.id.get) yield dt
[warn] ^

And if I use Query class directly, I get the same warning:
[warn] /home/salil/Scala/sd_ventures/app/models/DeviceType.scala:38: scala.slick.lifted.Column[Int] and Int are unrelated: they will most likely never compare equal
[warn] val dt = Query(DeviceTypes).filter(_.id == device_type.id.get)
[warn] ^

有人能告诉我为什么它不起作用吗?

最佳答案

在 Slick 中,您必须使用“===”来测试相等性。

val dt_query = for(dt <- DeviceTypes if dt.id === device_type.id.get) yield dt

引用:在 http://slick.typesafe.com/doc/1.0.0/gettingstarted.html 的底部

关于scala - 为什么光滑的投影不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15004936/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com