开发者

Unable to save domain objects until CRUD scaffold is used

I'm having the strangest problem with a controller in a Grails project. I am trying to do a simple update of a domain object. Here is a simplified version of the controller

def updateRecord = {
    def foundHVT = Process.get(params.hvt)

    foundHVT.summaryBy = params.summaryBy
    foundHVT.catalogBy = params.catalogBy
    foundHVT.editBy = params.editBy
    foundHVT.produceBy = params.produceBy
    foundHVT.correctedBy = params.correctedBy
    // a bunch more of these

    foundHVT.save(flush: true);

    redirect (action:resource, id: params.hvt)
}

If I run the a new instance of the application of and use this controller to update an object, it doesn't work, the object doesn't save. It will look fine within the controller. I can, for example, 开发者_JAVA百科re-query the object and the changes are there, post save.

Now here's where it gets weird. If i use the preset scaffold edit controller and update/save an domain object -- and then switch back to this "updateRecord" controller it works FINE until i shut down the server it is working on?!?

I realize I am missing something very basic, but I can't find what it is. Any guidance would be most graciously appreciated.

DM


As HVGOTCODES noted Grails Clean seems to have fixed whatever weirdness was going on with this controller.


try putting a "def scaffold=true" in your controller if it does not already have the normal entry points.


Probably scaffolding save fills some field that you don't.

Possible problems:

  1. Do check save() result and render foundHVT.errors the way Grails does. Add failOnError: true parameter to save() or just check foundHVT.hasErrors(). Look at foundHVT.errors.allErrors for validation problems.

  2. Why not foundHVT.properties = params?

  3. What is there is no foundHVT?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜