Question

In some examples, I'm seeing email:Pk[String] under the User class but in others I see id:Pk[Long] (both not assigned). A user can change their email as much as they want but the ID will not change so is there a (security) reason behind this?

Was it helpful?

Solution

I'm not sure if your question refers to NotAssigned or email:Pk[String], but to an answer both: not really. This SO post discusses the uses of Pk: What is purpose of anorm's Pk?

The purpose of something like case class User(id:Pk[Long] = NotAssigned, name:String) with the id being NotAssigned by default allows for a representation of a model that hasn't been persisted in the database yet. The id can later be filled in after saving.

I'm not sure why you would ever want email: Pk[String] = NotAssigned, as a user's email is a critical piece of information when persisting the model. Though it is certainly fine to use the email address as the primary key if you really don't care (or have) ids. Email addresses should at at least be set as a unique key in the database, anyway, since it should never be possible for two users to have the same email.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top