do you know why afterCreate methods are not invoked after creating the object? Look at this code:
val c = Company.create
println(">>> After create")
c.save
Which produces:
c: com.subeli.officebook.model.Company = 0
>>> After create
create packages
create packages
save packages
The Company model 开发者_运维问答looks like this:
object Company extends Company with LongKeyedMetaMapper[Company] with CRUDify[Long, Company] {
override def dbTableName = "company"
override def beforeCreate = createPackages _ :: super.beforeCreate
override def afterCreate = createPackages _ :: super.afterCreate
override def afterSave = savePackages _ :: super.afterSave
override def afterUpdate = savePackages _ :: super.afterUpdate
private def createPackages(c: Company): Unit = println("create packages")
private def savePackages(c: Company): Unit = println("save packages")
}
Thanks in advance, Etam.
The "lifecycle" that is being referred to by the callbacks is the database persistence lifecycle. So, in this case, the create that is being referred to is the actual creation, or INSERT, of the object in the database. Likewise, the beforeUpdate and afterUpdate refer to the moment before and after an UPDATE statement is sent to the database.
If you need to tap into the creation of the object, you can do that through the normal Scala mechanisms of a constructor or some factory to create the objects.
While I agree that it's somewhat of a misnomer, it is a misnomer that is very common throughout the various ORM products that exist.
精彩评论