Hmm, no movement on the Grails list? There is around 50 posts on there
per day.. what would you class as movement?
>
> I'm building a RESTful application in Grails, which basically serves
> information consumed by PHP clients. Given the following flow:
>
> 1) PHP sends a GET to /country/2, to get a specific country with ID = 2
> 2) Grails gets the request, maps it to the show method in the controller,
> and then returns an XML representation of the Country domain class with ID =
> 2 (let's assume for the sake of simplicity that it's just a class with ID
> (autogenerated) and name)
> 3) The resulting XML is send back to PHP, which uses it to show the info to
> the user
> 4) Now the user modifies the name of the country, and clicks update
> 5) PHP sends a PUT request to /country/2, with an XML that provides the new
> name for the specific Country with ID = 2
> 6) Grails gets the request, maps it to the update method in the controller,
> and here comes my issue.
>
> As these are two completely different, separated web apps (PHP & Grails),
> when I get the params in Grails about the XML sent by PHP with the PUT
> request, what should I do to update the object?
>
> I've tried to create a new country, using the "params.country" as a
> parameter to the constructor, so a new country is created, but then the ID
> is not assigned whatsoever. Next, I assign it manually (newCountry.id =
> params.id), but when I call newCountry.merge(), it ends up inserting a
> completely new record in the DB, as opposite to updating my existing country
> as expected.
Why are you calling merge() which is for detached instances. Have you
tried save()?
If it is still a problem raise an issue with an example of what you
are trying to achieve
Cheers
>
> Then, I took a look at how RoR solves this issue, and in this case, it
> firstly loads the country by ID, and then calls "update_attributes", passing
> as an argument the "params.country". Apparently, this method detects changes
> in the attributes, so when you merge the object back, everything is fine.
>
> As I haven't found such a similar behaviour in Grails, I've been forced to
> define a "updateAttributes" for each and every of my domain classes, so I
> was wondering whether there's a more generic way to attack this limitation.
>
> Thanks in advance.
>
> Regards,
> Enrique Medina.
>
--
Graeme Rocher
Grails Project Lead
G2One, Inc. Chief Technology Officer
http://www.g2one.com
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
def p = new CountryVO.get(params.id)
p.properties = params['countryVO']
Cheers
On Fri, Aug 1, 2008 at 5:07 PM, Enrique Medina Montenegro