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

  • SEARCH
  • Home
  • 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 8875907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:05:53+00:00 2026-06-14T19:05:53+00:00

The Slick DSL allows two ways to create optional fields in tables. For this

  • 0

The Slick DSL allows two ways to create optional fields in tables.

For this case class:

case class User(id: Option[Long] = None, fname: String, lname: String)

You can create a table mapping in one of the following ways:

object Users extends Table[User]("USERS") {
    def id = column[Int]("id", O.PrimaryKey, O.AutoInc)
    def fname = column[String]("FNAME")
    def lname = column[String]("LNAME")
    def * = id.? ~ fname ~ lname <> (User, User.unapply _)
  }

and

  object Users extends Table[User]("USERS") {
    def id = column[Option[Long]]("id", O.PrimaryKey, O.AutoInc)
    def fname = column[String]("FNAME")
    def lname = column[String]("LNAME")
    def * = id ~ fname ~ lname <> (User, User.unapply _)
  }
}

What is the difference between the two? Is the one the old way and the other the new way, or do they serve different purposes?

I prefer the second choice where you define the identity as optional as part of the id definition because it’s more consistent.

  • 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-14T19:05:54+00:00Added an answer on June 14, 2026 at 7:05 pm

    The .? operator in the first one allows you to defer the choice of having your field be optional to the moment of defining your projections. Sometimes that’s not what you want, but defining your PK to be an Option is perhaps a bit funny because one might expect a PK to be NOT NULL.

    You can use .? in additional projections besides *, for example:

    def partial = id.? ~ fname
    

    Then you could do Users.partial.insert(None, "Jacobus") and not worry about fields you’re not interested in.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have wrapped some header into two line using this. .slick-column-name { white-space: normal;
I'm trying to be slick and I'm putting this user control in a div
I need to create a color animation. I have a control (a slick button
I have seen a slick method for upgrading user data from one iOS app
I'm using <script> $(#a-slots-16-history div:nth-child(odd)).addClass(function() { return slick-toggle + $(this).index(); }); </script> to give
I'm using Slick Util's Texture class to load textures for lwjgl, but apparently that
I've found this nice slick effect in here - http://www.red-team-design.com/wp-content/uploads/2011/04/css3-box-shadow.html . Here is a
Are there any slick ways to style/template a WPF ItemsControl differently based off whether
I'm using slick in a scala project to query some tables. //define table object
JFLAGS = -d bin -cp lib/slick.jar:lib/lwjgl.jar JC = javac .SUFFIXES: .java .class .java.class: $(JC)

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.