How do I store user case objects with squeryl? I have an Account object with a permission field of type Permission (defined as a sealed trait). I also have 2 case objects (Administrator and NormalUser) extending from Permission. How can I persist the Account class using Squeryl. Example code below:
sealed trait Permission
case object Administrator extends Permission
case object NormalUser extends Permission
case class Account(
id: Long,
email: String,
permission: Permission
) extends KeyedEntity[Long]
Expanding on my comment, if you use a custom type to retrieve the permission type, such that it persists to the database as an integer (in the example below 1 and 0), you can override the unapply method to lookup the case object and pattern matching should work fine. I imagine something like the following should work:
Then you should be able to store the permission directly in your code, using your entity definition:
you can set the
permissionfield directly asAdministratororNormalUserand you should also be able to pattern match like: