Scala 如何使用SORM在我的模型上包括时间戳(创建时间戳和更新时间戳)?
ActiveRecord句柄时间戳执行以下操作:Scala 如何使用SORM在我的模型上包括时间戳(创建时间戳和更新时间戳)?,scala,sorm,Scala,Sorm,ActiveRecord句柄时间戳执行以下操作: 插入数据?已定义在处创建的 更新数据?更新的_at被重新定义 我将如何使用SORM进行此操作?乍一看,类似的操作可能会奏效: import org.joda.time._ object Db extends Instance (entities = ...) { override def save [T <: AnyRef : TypeTag] ( v : T ) = v match { case v :
- 插入数据?已定义在处创建的
- 更新数据?更新的_at被重新定义
我将如何使用SORM进行此操作?乍一看,类似的操作可能会奏效:
import org.joda.time._
object Db extends Instance (entities = ...) {
override def save [T <: AnyRef : TypeTag] ( v : T )
= v match {
case v : Artist with Persisted =>
super.save( v.copy( updatedAt = DateTime.now() ) )
case v : Artist =>
super.save( v.copy( createdAt = DateTime.now() ) )
// ... so on for other entities
case v =>
super.save(v)
}
}
我得告诉你,整个问题对我来说不是很自然。我无法想象这种行为会有什么好处。但我再次向你介绍了选择
import org.joda.time._
case class Artist
( name : String,
updatedAt : DateTime = DateTime.now(),
createdAt : DateTime = DateTime.now() )
object Db extends Instance (entities = ...) {
override def save [T <: AnyRef : TypeTag] ( v : T )
= v match {
case v : Artist with Persisted =>
super.save( v.copy( updatedAt = DateTime.now() ) )
case v =>
super.save(v)
}
}