Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8785769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:26:53+00:00 2026-06-13T21:26:53+00:00

How do I store user case objects with squeryl? I have an Account object

  • 0

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]
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T21:26:54+00:00Added an answer on June 13, 2026 at 9:26 pm

    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:

    class Permission(identifier:Int) extends org.squeryl.customtypes.IntField(identifier) {
      self: CustomType[Int] =>
    
      private lazy val permissions = 
        List(Administrator, NormalUser).
          map(p => p.value -> p).
          toMap
    
      def unapply = permissions.get(value)
    }
    
    case object Administrator extends Permission(1)
    case object NormalUser extends Permission(0)
    

    Then you should be able to store the permission directly in your code, using your entity definition:

    case class Account(
            id: Long, 
            email: String,
            permission: Permission
    ) extends KeyedEntity[Long]
    

    you can set the permission field directly as Administrator or NormalUser and you should also be able to pattern match like:

    account.permission match {
      case Administrator => ..
      case NormalUser => ..
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an object called users that I use to store user objects that
In our project we need to store some object (User, for example) and also
I have an object that represent's a User's account on my site, and a
I have several objects which are assigned attributes based on user input. I then
When I create a Data transfer Object (DTO) which I use to store user
I would like to handle the case where a user is editing an object
I have created a custom User profile template and object in the core database
I have a generic dictionary of objects where the key is of type Type
I have a list of objects and each and every object in the list
I store user editable articles in a database. Users can insert some simple widgets

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.