on slick 2.0, I find I can not implicit user defined column

拟墨画扇 提交于 2019-12-13 08:46:20

问题


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



来源:https://stackoverflow.com/questions/20828136/on-slick-2-0-i-find-i-can-not-implicit-user-defined-column

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!