Details
-
Type:
New Feature
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: None
-
Fix Version/s: 2.3-M2
-
Component/s: None
-
Labels:None
Description
Is there any reason why there are afterInsert, beforeInsert, afterUpdate, beforeUpdate but no afterSave or beforeSave in domain classes?
I mean, most of the times I do something like:
class MyDomainClass {
def afterSave =
def afterInsert = afterSave, afterUpdate = afterSave
}
It would also be awesome if one could get access to the old properties in an afterSave/afterUpdate event.
Also, I find it very limiting that we can't do something like that:
class MyDomainClass {
def afterUpdate()
}
In several times I need the save operation to be finished before returning from afterUpdate. Also, in an afterSave of AnotherDomainClass, I would expect the instance of MyDomainClass to be persisted in the database.
Is it possible for Grails to implement such helpful behavior?
Thanks,
Rodrigo.
For your last problem. As described in the documentation, any new persistence logic in an even should be surrounded by withNewSession:
class MyDomainClass { def afterUpdate(){ withNewSession { new AnotherDomainClass(name: 'Something').save(flush: true) } } }