This project is archived and is in readonly mode.
to_xml format with sti
Reported by Slava | July 24th, 2009 @ 07:14 PM | in 3.x
Hello,
I use STI for some models and there seems to be a problem with xml
served. here is my setup
class SalesDocument < ActiveRecord::Base
has_many :items
end
class SalesQuotation < SalesDocument
end
class SalesOrder < SalesDocument
end
when all records are sales_quotations xml returned on /sales_documents.xml is the same as /sales_quotations.xml
or when all records are sales_orders xml returned on /sales_documents.xml is the same as /sales_orders.xml
<sales-orders type="array">
<sales-order>
<customer-id type="integer" nil="true"></customer-id>
<delivery-date type="date">2009-07-24</delivery-date>
<id type="integer">2053932786</id>
<net-value type="float" nil="true"></net-value>
<items type="array">
<item>
<id type="integer">2053932786</id>
<line>10</line>
<quantity type="float" nil="true"></quantity>
<sales-document-id type="integer">2053932786</sales-document-id>
</item>
</items>
</sales-order>
</sales-orders>
but when some of the records are sales_quotations and some are sales_records /sales_documents.xml returns
<records type="array">
<record>
<customer-id type="integer" nil="true"></customer-id>
<delivery-date type="date">2009-07-24</delivery-date>
<id type="integer">2053932786</id>
<net-value type="float" nil="true"></net-value>
<items type="array">
<item>
<id type="integer">2053932786</id>
<line>10</line>
<quantity type="float" nil="true"></quantity>
<sales-document-id type="integer">2053932786</sales-document-id>
</item>
</items>
</record>
<record>
<customer-id type="integer" nil="true"></customer-id>
<delivery-date type="date">2009-07-24</delivery-date>
<id type="integer">2053932787</id>
<net-value type="float" nil="true"></net-value>
<items type="array"/>
</record>
</records>
I am assuming the correct format should be
<sales-documents type="array">
<sales-order>
...
</sales-order>
<sales-quotation>
...
</sales-quotation>
</sales-documents>
Interestingly /sales_documents.json returns correct set of elements
[
*
-
{
o
-
sales_order: {
+ delivery_date: "2009-07-24"
+ id: 2053932786
+ net_value: null
+ customer_id: null
+
-
items: [
#
-
{
* quantity: null
* line: "10"
* sales_document_id: 2053932786
* id: 2053932786
}
]
}
}
*
-
{
o
-
sales_quotation: {
+ delivery_date: "2009-07-24"
+ id: 2053932787
+ net_value: null
+ customer_id: null
+
-
items: [
]
}
}
]
Comments and changes to this ticket
-
Jeremy Kemper August 31st, 2009 @ 08:17 AM
- Assigned user set to Jeremy Kemper
- State changed from new to open
Agreed. I've been bitten by this difference several times. Works with a single record.to_xml(:include => :association) but not association.to_xml.
-
Dan Pickett May 9th, 2010 @ 07:23 PM
- Tag set to bugmash
-
Neeraj Singh May 9th, 2010 @ 10:37 PM
In the edge this is what you would get today.
<pre> <sales-documents type="array"> <sales-document> ... </sales-document> <sales-document> ... </sales-document> </sales-documents> </pre>
If this is acceptable then this ticket can be closed.
However if the desired output is
<pre> <sales-documents type="array"> <sales-order> ... </sales-order> <sales-quotation> ... </sales-quotation> </sales-documents> </pre>
then I am willing to work on it. Lemme know.
Edited by Rohit Arondekar to fix formating.
-
Neeraj Singh May 9th, 2010 @ 10:48 PM
Can someone ask lighthouse app team to put "preview" button next to "Update ticket" . Stackoverflow nails usability issue with live preview.
-
Rohit Arondekar June 15th, 2010 @ 11:10 AM
Any updates on this ticket? Is output that Neeraj has shown acceptable?
-
Rohit Arondekar June 21st, 2010 @ 08:21 AM
I fixed the formating of the comment made by Neeraj. Does this need more work or is the output acceptable?
-
Neeraj Singh June 22nd, 2010 @ 11:43 AM
Rohit: Thanks for the ping. I guess the ball is in the court of one of the rails core team members. If the present output is acceptable then all is fine. Peace.
Also thanks to Rohit for correcting the formatting in my previous comment.
-
Neeraj Singh July 1st, 2010 @ 04:18 AM
- Importance changed from to
Hi Jeremy I believe this is no longer an issue. Please take a look an earlier comment by me (edited by Rohit. thank you) to see the output that is generated currently. Then you can decide if that is good enough.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>