on slick 2.0, I find I can not implicit user defin

2019-09-21 01:47发布

问题:

I use slick 2.0 rc I have defined field 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)

when I use it:

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)
}

it give me compile error as:

[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:

This seems to be a duplicate of the already answered question, which can be found here: on slick 2.0, I find I can not store user defined field



标签: scala slick