Created
May 27, 2009 18:18
-
-
Save tednaleid/118797 to your computer and use it in GitHub Desktop.
alternate way to replace GORM save method and add named parms
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() | |
def oldSave = clazz.metaClass.getMetaMethod("save", [java.util.Map] as Class[]) | |
clazz.metaClass.save = { java.util.Map args -> | |
if (args.bleat) println "Bleating out args: $args" | |
return oldSave.invoke(delegate, args) | |
} | |
// prints: | |
// Bleating out args: [bleat:true, flush:true] | |
// Foo : 1 | |
println new Foo(name: "foo1").save(bleat: true, flush: true) | |
// prints: Foo : 2 | |
println new Foo(name: "foo2").save(flush: true) | |
// prints: Foo : 3 | |
println new Foo(name: "foo3").save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment