我想在一个包含用户定义类型(枚举)的列中使用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 功能,而我却漏掉了?
谢谢