我的案例类为 Target does not support branch tracing.
UserAccount
和case class UserAccount(Id: Option[Long], Name: String, occupation: Occupation)
Occupation
我使用play slick 3
创建了一个模式sealed trait Occupation
object Occupation {
case object Teacher extends Occupation
case object Student extends Occupation
case object Others extends Occupation
}
当我试图运行该项目时。由于列class AccountSchema(tag: Tag) extends Table[UserAccount](tag, "user_account") {
def id = column[Long]("id", O.PrimaryKey, O.AutoInc)
def name = column[String]("name")
def occupation = column[Occupation]("occupation")
def * = (id.?, name, occupation) <>((UserAccount.apply _).tupled, UserAccount.unapply)
}
如何在光滑的表列中使用对象占用?
答案 0 :(得分:1)
您需要添加从关系模型到对象模型的映射,反之亦然。
sealed trait Occupation
object Occupation {
implicit val occupationType = MappedColumnType.base[Occupation, String](
{ occupation => if(occupation==Teacher) "Teacher" else if (occupation == Student) "Student" else "Others"},
{ occupation => if(occupation == "Teacher") Teacher else if (occupation == "Student") Student else Others }
)
case object Teacher extends Occupation
case object Student extends Occupation
case object Others extends Occupation
}
以下是更多详情:http://slick.typesafe.com/doc/3.0.0/userdefined.html