Created
May 27, 2009 01:28
-
-
Save tednaleid/118407 to your computer and use it in GitHub Desktop.
adding arguments to GORM save through metaClass
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// do this in the plugins doWithDynamic methods on each domain class: | |
def domainClass = grailsApplication.getDomainClass("Foo") | |
def clazz = domainClass.clazz | |
// prime the pump to get the GORM methods actually decorated and available on the meta class | |
clazz.count() | |
clazz.metaClass.invokeMethod = { String name, args -> | |
if (name == "save" && args[0] instanceof Map) { | |
Map saveArgs = args[0] | |
if (saveArgs.bleat) { | |
println "Bleating out $saveArgs" | |
} | |
} | |
return clazz.metaClass.getMetaMethod(name, args).invoke(delegate, args) | |
} | |
def f = new Foo(name: "bar") | |
f.save(bleat: true) // prints out "Bleating out [bleat: true]" and then saves the object |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment