【发布时间】:2012-12-19 06:49:35
【问题描述】:
Squeryl 0.9.6 版引入了一种新方法来声明具有关联主键through the use of the KeyedEntityDef typeclass 的类。还是老办法声明
import org.squeryl.KeyedEntity
case class Foo(id: Long, myField: String) extends KeyedEntity[Long]
支持。
我正在尝试将使用 Squeryl 0.9.5 的现有应用程序迁移到新版本,以使用自定义原始类型,但我遇到了编译问题。这是一个不再编译的特征示例
trait Retrievable[A <: KeyedEntity[Long]] {
def table: Table[A]
def get(id: Long): Option[A] = inTransaction {
table.lookup(id)
}
}
它本来是这样使用的:
case class Foo(id: Long, myField: String) extends KeyedEntity[Long]
object Foo extends Retrievable[Foo] {
def table = DB.something
}
...
val foo = Foo.get(235)
现在,当我尝试编译时,我收到了消息
该方法需要一个隐式的 org.squeryl.KeyedEntityDef[A, Long] in 范围,或者它扩展了特征 KeyedEntity[{K}]
虽然A 确实扩展了KeyedEntity[Long]。甚至添加一个隐含的范围,比如
trait Retrievable[A <: KeyedEntity[Long]] {
def table: Table[A]
implicit val ev: <:<[A, KeyedEntity[Long]]
def get(id: Long): Option[A] = inTransaction {
table.lookup(id)
}
}
无助于隐式解析,trait 无法编译。
有没有人知道为什么编译器没有提供 lookup method 中的隐含内容?
【问题讨论】:
标签: scala implicit-conversion squeryl