您需要使用EnumColumn
,這是爲此原因而創建的。如果你想使用枚舉作爲鍵,那麼你還需要使用默認的輔助方法創建一個基元。
您可以同時使用定義枚舉的兩種風格。
object Records extends Enumeration {
type Records = Value
val TypeOne, TypeTwo, TypeThree = Value
}
object NamedRecords extends Enumeration {
type NamedRecords = Value
val One = Value("one")
val Two = Value("two")
}
object enum extends EnumColumn[Records.type](this, Records)
你的情況,這將是:
object role extends EnumColumn[UserRole.type](this, UserRole)
以此爲索引,你將需要:
implicit val userRolePrimitive = Primitive(UserRole)
更新作爲幻影2.0.0+
的
object role extends EnumColumn[UserRole](this)
您不需要定義任何額外的含義,現在Enums現在被支持爲索引。
我看到,IntelliJ Idea在代碼編譯時在下面的行顯示錯誤。 對象角色擴展EnumColumn(this,UserRole){覆蓋lazy val name =「role」} 所以,它的工作原理。 – PainPoints