What I want to do is find a domain and then either create a new one or save the pre-existing one. Here is the code that I am currently working with (in this project, skeleton is the package name):
def save() {
Class lob = grailsApplication.getDomainClass('skeleton.'+params.lob.name)
def instance = lob.get(params.lob.id)
if (instance){
params.data.each { name, value ->
if (instance.metaClass.hasProperty(name)){
instance[name] = value
}
}
}else{
instance = new lob()
params.data.each { name, value ->
if (instance.metaClass.hasProperty(name)){
instance[name] = value
}
}
}
}
This doesn’t seem to be working. Can anyone help me with the solution?
The object returned by
getDomainClassis an instance ofGrailsDomainClass. To get the actual domain class on which you can callget, first callgetClazzon it. For example:In addition, you’ll have to call
newInstanceon the class object rather than using thenewkeyword to create a new instance.