【发布时间】:2013-11-20 07:50:38
【问题描述】:
在 Slick 2 中,我们可以像这样映射表:
case class Cooler(id: Option[Int], minTemp: Option[Double], maxTemp: Option[Double])
/**
* Define table "cooler".
*/
class Coolers(tag: Tag) extends Table[Cooler](tag, "cooler") {
def id = column[Int]("id", O.PrimaryKey, O.AutoInc)
def minTemp = column[Double]("min_temp", O.Nullable)
def maxTemp = column[Double]("max_temp", O.Nullable)
def * = (id.?, minTemp.?, maxTemp.?) <> (Cooler.tupled, Cooler.unapply _)
}
object Coolers {
val tableQuery = TableQuery[Coolers]
}
因为我有很多表,我想为它们定义通用方法,例如find、delete、update,所以我必须在一个超类中定义这些方法,从哪里扩展我的对象( object Coolers extends TableUtils[Coolers, Cooler])。为了定义这些方法,我需要tableQuery 移出我在这个超类中的对象,所以我试了一下:
abstract class TableUtils[T <: Table[A] , A] {
val tableQuery = TableQuery[T]
}
但我收到tableQuery 定义错误:
class type required but T found
有人知道我做错了什么吗?
【问题讨论】: