3

何らかの理由で、私の場合、単純な Slick テーブル宣言でさえ機能しません。Maven 中央リポジトリの最新の slick 2.10 (1.0.0) を使用しています。

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]                                               ^

なぜ機能しないのか誰か教えてもらえますか?

4

1 に答える 1

11

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の下部

于 2013-02-21T15:06:36.287 に答える