【发布时间】:2013-06-19 03:07:26
【问题描述】:
我正在关注 Slick documentation example for autoincrementing fields,但在创建 mapped projection 时遇到了问题……嗯,只有一列。
case class UserRole(id: Option[Int], role: String)
object UserRoles extends Table[UserRole]("userRole") {
def id = column[Int]("ID", O.PrimaryKey, O.AutoInc)
def role = column[String]("ROLE")
// ...
def * = id.? ~ role <> (UserRole, UserRole.unapply _)
// NEXT LINE ERRORS OUT
def forInsert = role <> ({t => UserRole(None, t._1)}, {(r: UserRole) => Some((r.role))}) returning id
}
错误是“值 不是 scala.slick.lifted.Column[String] 的成员”
我还认为这样设计我的架构会更有效:
case class UserRole(role: String)
object UserRoles extends Table[UserRole]("userRole") {
def role = column[Int]("ROLE", O.PrimaryKey)
// ...
def * = role <> (UserRole, UserRole.unapply _)
}
但后来我也开始遇到与上述相同的错误。 "value 不是 scala.slick.lifted.Column[String] 的成员"
我到底在做什么?我只是没有projection 因为我只有一列吗?如果是这样,我应该怎么做?
【问题讨论】:
标签: scala projection slick