Forum: Ruby on Rails inconsistency in calling to_xml on STI returning <record>

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Bc1eb24764e123c9dac1c9dcf66c7fda?d=identicon&s=25 Zhao Lu (Guest)
on 2008-10-19 21:48
(Received via mailing list)
Hi,

When calling to_xml on STI that returns heterogeneous type of records,
each record is contained in <record> node.
For example, if I have Account with subclasses EmailAccount and
PhoneAccount, Account.find(:all).to_xml gives me:
<record>
   <emailaddress1 ...>
</record>
<record>
  <phonenumber1..>
</record>

When calling to_xml on homogeneous type of records, each record is
contained in the node with the type.
For example, Account.find(:all, :conditions=>{:type => 'PhoneAccount'})
<phone_account>
  <phonenumber1...>
</phone_account>

I feel this makes writing test and client-side parsing difficult.  I
did some search and didn't find anything solutions (except a trac
ticket opened over a year ago with status open).  I also feel this is
probably a often-encountered issue and have some
pragmatic solution.  Any suggestion is appreciated.

Thanks,

--
Zhao
This topic is locked and can not be replied to.