0

I've got a fairly simple Grails app against a DB2 database. Everything works fine except when I try to update a record. show() and edit() are able to find the record , but the update fails saying that it cannot be located. Here's the edit:

    def edit() 
{
    def flatAdjustmentInstance = FlatAdjustment.get( new FlatAdjustment(compPayeeID: params["compPayeeID"], effectiveQuarterBeginDate: params["effectiveQuarterBeginDate"]) ) //here are your inbound params

    if(!flatAdjustmentInstance)
    {
        flash.message = "MRI Modifier Record not found with ${params}"
        redirect(action:"list")
    }
    else
    {
        return [ flatAdjustmentInstance: flatAdjustmentInstance]
    }
}

Now the update()

def flatAdjustmentInstance = FlatAdjustment.get( new FlatAdjustment(compPayeeID: params["compPayeeID"], effectiveQuarterBeginDate: params["effectiveQuarterBeginDate"]) ) //here are your inbound params
    //def flatAdjustmentInstance = new FlatAdjustment(compPayeeID: params["compPayeeID"], effectiveQuarterBeginDate: params["effectiveQuarterBeginDate"])

    if (!flatAdjustmentInstance) 
    {

        flash.message = message(code: 'default.not.found.message', args: [message(code: 'flatAdjustment.label', default: 'FlatAdjustment'), params])
        redirect(action: "list")
        return
    }

As I said, all controller methods/closures create the instance of the domain object in the same way and all work correctly except for update(). Any ideas?

4

2 回答 2

0

.get() retrieves an existing object based on its ID. You cannot pass a new object to that method.

FlatAdjustment flatAdjustmentInstance = FlatAdjustment.findByCompPayeeIDAndEffectiveQuarterBeginDate(params.compPayeeID, params.date("effectiveQuarterBeginDate", "INSERTYOURDATEFORMATHERE"))

于 2013-03-30T04:14:56.450 回答
0

I figured this one out, and it was a really bone-headed mistake. The form I had created was passing in the compPayeeID, but since the field is not editable by the user, I changed it from an input to a textField. That meant is was no longer being passed in with the grails params object. I changed it back, set the field to read only, and now all is well.

于 2013-04-01T21:52:43.503 回答