【发布时间】:2014-02-09 03:48:18
【问题描述】:
我正在尝试将 Slick 与具有用户定义类型(枚举)的列一起使用。在我尝试编写使用该列的查询之前,一切正常。
编译时出现以下方法错误:
def findCredentials(credentialType:CredentialType)(implicit session: Session): List[Credential] = {
val query = for {
c <- credentials if c.credentialType === credentialType
} yield c
query.list
}
这是错误:
[error] ... value === is not a member of
scala.slick.lifted.Column[models.domain.enumeration.CredentialType.CredentialType]
[error] c <- credentials if c.credentialType === credentialType
枚举代码在这里:
object CredentialType extends Enumeration {
type CredentialType = Value
val Password, Token = Value
}
表定义在这里:
case class Credential(id: Long, userId: Long, credentialType: CredentialType)
class Credentials(tag: Tag) extends Table[Credential](tag, "credential") {
implicit val credentialTypeColumnType = MappedColumnType.base[CredentialType, String](
{ c => c.toString },
{ s => CredentialType.withName(s)}
)
def id = column[Long]("id", O.PrimaryKey, O.AutoInc)
def userId = column[Long]("user_id")
def credentialType = column[CredentialType]("type")
def * = (id, userId, credentialType) <> (Credential.tupled, Credential.unapply)
}
我搜索了许多其他问题,但它们要么不适用于 slick 2.x.x,要么不涉及枚举类型。
我的问题是,我是否需要在某处为枚举类型定义 === 运算符,或者是否有更简单的方法使用我缺少的当前 slick 2.0.0 功能?
谢谢
【问题讨论】:
标签: scala comparison enumeration slick