In looking at the to_xml method and its behavior on associations, currently it includes the attributes from the associations into the same hash that represents that AR instance being serialized. Wouldn''t it be better to have to_xml call to_xml on the association''s AR instances? I would like to override a particular model''s to_xml and would like the model that has a has_many relationship to it use the overriden to_xml, but currently that doesn''t work. Where I need this is in exposing via a REST style interface a key/value property model that is implemented in the table using separate date, numeric, boolean and string types for fast indexing. I want to hide this implementation detail from the REST client and only want to expose a single value() method to the to_xml. This works using to_xml(:method => :value, :only => []) in the model itself, but then the other models that have associations with this model need to know that also, which seems like a DRY violation. If people like this idea, I''ll code up a patch for it. Regards, Blair -- Blair Zajac, Ph.D. <blair@orcaware.com> Subversion training, consulting and support http://www.orcaware.com/svn/
On May 3, 2006, at 5:23 PM, Blair Zajac wrote:> In looking at the to_xml method and its behavior on associations, > currently it includes the attributes from the associations into the > same hash that represents that AR instance being serialized. > > Wouldn''t it be better to have to_xml call to_xml on the > association''s AR instances?Definitely. This is the way I''ve done it in the past, when I had to roll my own, and I think it makes sense.> > If people like this idea, I''ll code up a patch for it. >Please do. :) -- Benjamin Curtis http://www.tesly.com/ -- Collaborative test case management http://www.agilewebdevelopment.com/ -- Resources for the Rails community
Benjamin Curtis wrote:> On May 3, 2006, at 5:23 PM, Blair Zajac wrote: > >> In looking at the to_xml method and its behavior on associations, >> currently it includes the attributes from the associations into the >> same hash that represents that AR instance being serialized. >> >> Wouldn''t it be better to have to_xml call to_xml on the association''s >> AR instances? > > > Definitely. This is the way I''ve done it in the past, when I had to > roll my own, and I think it makes sense. > >> >> If people like this idea, I''ll code up a patch for it.I put a patch up at http://dev.rubyonrails.org/ticket/4989 It includes test suite and I added a :dasherize => false feature that disables the dasherizing of names. I plan on using Python''s xmltramp as a REST client and not changing the column names in the XML will make it a little easier to have RoR accept the XML back and update the model. Regards, Blair -- Blair Zajac, Ph.D. <blair@orcaware.com> Subversion training, consulting and support http://www.orcaware.com/svn/