Tôi đang theo dõi Slick documentation example for autoincrementing fields và tôi đang gặp sự cố khi tạo một mapped projection rằng ... tốt, chỉ có một cột.Dự báo Scala trong Slick chỉ với một cột
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
}
Lỗi này là "giá trị <> không phải là thành viên của scala.slick.lifted.Column [Chuỗi]"
Tôi cũng nghĩ rằng nó sẽ có hiệu quả hơn để thiết kế sơ đồ của tôi như sau:
case class UserRole(role: String)
object UserRoles extends Table[UserRole]("userRole") {
def role = column[Int]("ROLE", O.PrimaryKey)
// ...
def * = role <> (UserRole, UserRole.unapply _)
}
Nhưng sau đó tôi cũng bắt đầu gặp lỗi tương tự như trên. "value <> không phải là thành viên của scala.slick.lifted.Column [String]"
Tôi đang thực sự làm gì? Tôi có không còn projection nữa vì tôi chỉ có một cột không? Nếu vậy, bạn cần làm gì ?