我正在遵循Slick文档中有关自增字段的示例,但我在创建映射投影时遇到了问题...只有一个列。
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
}
错误是"value <> is not a member of 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 <> is not a member of scala.slick.lifted.Column[String]"
我到底在做什么?我只有一列,难道我没有投影了吗?如果是这样,我应该做些什么呢?