1

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?

TheKojuEffect
  • 20,103
  • 19
  • 89
  • 125

1 Answers1

1

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
}
dmahapatro
  • 49,365
  • 7
  • 88
  • 117
  • Thanks. Is there any workaround I can do? Or else, can you please instruct me some guidance to use cloned repo in my project? – TheKojuEffect May 13 '14 at 06:34
  • [Here](http://stackoverflow.com/a/16116125/2051952) is how you can use an inline plugin. If the plugin is cloned to a location same as your app (for example) then you can use as `grails.plugin.location.'audit-logging' = "../grails-audit-logging-plugin/grails-audit-logging-plugin"` (note the repo is a wrapper over the plugin and a test application) – dmahapatro May 13 '14 at 06:41
  • 1
    [Latest version of plugin v1.0.1](http://grails.org/plugin/audit-logging) is released today with the above PR. You can use it now. Hope that helps. @TheKojuEffect – dmahapatro May 15 '14 at 22:10