ActiveResource and handling of arrays

ActiveResource uses xml_simple from activesupport to turn XML to
essentially a big Hash or Array, after which point
ActiveResource::Base’s load() (actually find_or_create_resource_for,
called from load) takes care of the remaining magic of building
ActiveResource::Base instances to encapsulate the parsed XML data.

Currently, if you have some XML that looks roughly like this:

1 blah blah ... ... ...

What happens is that you get an AR instance for my_model, in which you
have an attribute called “related_entities” which is a Hash, and which
contains a single attribute called “related_entity” which is an Array.
This makes sense given xml_simple’s parse/collapse/merge trickery,
but seems counter-intuitive for ActiveResource. I’d rather expect to
have an AR instance for my_model, with a “related_entities” attribute
which is itself immediately an Array of related_entity AR children.

Make sense?


Bosko M. [email protected]

I see Jeremy K. commited a fix for this not too long after the post:

r5167 | bitsweat | 2006-09-22 17:29:54 -0400 (Fri, 22 Sep 2006) | 1 line
workaround collections loaded as :people => { :person => [{…attrs…},
{…attrs…}] }

Thank you!

-B

On 9/22/06, Bosko M. [email protected] wrote:

<some_attrib>blah blah</some_attrib>
have an attribute called “related_entities” which is a Hash, and which
http://www.crowdedweb.com/


Bosko M. [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs