Reputation: 6999
I am experimenting with Anorm library of Playframework v2 in Scala. I have a case class like below
case class User (
id:Pk[Long] = NotAssigned, // auto increment value in mysql
name: String
updated_at: Date // assigned through a trigger by Database
)
val testUser = new User(NotAssigned:Pk[Long], "Ali", null)
Is it find to use null for fields such as updated_at which their values are assigned directly through DB ? How about using something like Pk[Date] ? I suppose I don't understand the Pk type in Anorm correctly.
I appreciate your comments,
Upvotes: 1
Views: 285
Reputation: 4873
I think assigning null
values is never a good idea. I'm using a default date instead. You should then omit the default values when constructing new values of type User
(the new
keyword is unnecessary for Scala's case classes):
case class User (
id:Pk[Long] = NotAssigned,
name: String
updated_at: Date = new Date(0) //1970-01-01
)
val testUser = User("Ali")
Upvotes: 2
Reputation: 9663
If this value is automatically set by your database you should not need to set it by yourself. Thus, it should not appear in your write operations.
Upvotes: 1