Question

I'm trying to use grails audit-logging plugin. It seems to do what I need to do.

But, I'm having problem referencing id for a domain class where id is automatically generated.

class Person {
 static auditable = true

 String name
 String email


 def onSave = { newState ->
     println "new person inserted"

     // I want to get id of newly inserted person 
     // When I do newState[id], I get null

     // newState[name] works as expected
 }

}

When I try to reference id as for other attributes, I get null.

How can I get reference to id so that I can get id of newly inserted Person entity?

Was it helpful?

Solution

Recently a Pull Request was merged to do exactly what is being looked for.

A snapshot build (1.0.1-SNAPSHOT) will be available soon following which there will be a release build (1.0.1) asap. In the mean time you can clone the plugin and use it inline.

As part of the above PR id is made available for onSave event hook, but right now it is already available for logging and to enable id logging to AuditEventLog table there is a config setting provided by the plugin as:

//Config.groovy
auditLog {
    logIds = true // to log ids of objects in audit table
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top