1

如何检查对象是否已保存到数据库(例如通过匹配其 id)?

类似于以下代码段的内容:

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

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

}
4

1 回答 1

1

在此示例中,您需要:

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
  }   
}
于 2012-09-09T11:01:34.473 回答