2013-06-21 30 views
9

我正在關注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 [字符串]中的一員」

我還以爲它會是更有效的設計我的架構,如下所示:

case class UserRole(role: String) 

object UserRoles extends Table[UserRole]("userRole") { 
    def role = column[Int]("ROLE", O.PrimaryKey) 
    // ... 
    def * = role <> (UserRole, UserRole.unapply _) 

} 

但是,然後我開始得到與上面相同的錯誤。 「值<>不是scala.slick.lifted.Column [String]的成員」

我真的在做什麼?我只是沒有projection,因爲我只有一列?如果是這樣,應該我在做什麼?

回答