在slick 2.0上,我发现我无法隐式用户定义列

时间:2013-12-29 17:38:42

标签: scala slick

我使用slick 2.0 rc 我已经定义了字段UserId

trait TypedId extends Any {
   def value: Long
}

trait HasId[ID <: TypedId] {
  _: Table[_] =>
  def id: Column[ID]
}

case class UserId(value:Long) extends AnyVal with TypedId

case class User(id: Option[UserId],
                email: String,
                firstName: String,
                lastName: String,
                phone:String)

当我使用它时:

class Users(tag: Tag) extends Table[User](tag, "users") with HasId[Option[UserId]] {
    def * = (id.?, email, firstName , lastName , phone )<> (User.tupled, User.unapply)
    def id= column[Option[UserId]]("ID", O.AutoInc, O.PrimaryKey)
    def email = column[String]("EMAIL", O.NotNull)

    def firstName = column[String]("FIRST_NAME", O.NotNull)

    def lastName = column[String]("LAST_NAME", O.NotNull)
    def phone =column[String]("PHONE", O.NotNull)
}

它给我编译错误:

[error] C:\assigment\slick-advanced\app\models\User.scala:27: could not find imp
licit value for parameter tm: scala.slick.ast.TypedType[Option[models.UserId]]
[error]   def id= column[Option[UserId]]("ID", O.AutoInc, O.PrimaryKey)

1 个答案:

答案 0 :(得分:0)

这似乎与已经回答的问题重复,可在此处找到:on slick 2.0, I find I can not store user defined field