Question

How to check if the object was already been saved to database ( e.g. by matching its id)?

Something similar to the following snippet:

case class User(id: Pk[Long], name:String) {

    def loaded = id match {
      case NotAssigned => false  
      case Pk(refererId) => true
    }   

}
Was it helpful?

Solution

In this example, you want:

import anorm.Id        // if you don't already have import anorm._

case class User(id: Pk[Long], name:String) {
  def loaded = id match {
    case NotAssigned => false  
    case Id(refererId) => true
  }   
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top