Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

to_xml format with sti

#2952

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: [
                  ]
            }
      }

]

Reported by Slava · July 24th, 2009 @ 07:14 PM

State: resolved
Milestone: 3.x
Assigned to: Jeremy Kemper Jeremy Kemper
Importance: none

Activity

  1. Jeremy Kemper
    Jeremy Kemper
    • 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.

    August 31st, 2009 @ 08:17 AM

  2. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.x to 3.x

    May 4th, 2010 @ 06:48 PM

  3. Dan Pickett
  4. Neeraj Singh
    Neeraj Singh

    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.

    May 9th, 2010 @ 10:37 PM

  5. Neeraj Singh
    Neeraj Singh

    Can someone ask lighthouse app team to put "preview" button next to "Update ticket" . Stackoverflow nails usability issue with live preview.

    May 9th, 2010 @ 10:48 PM

  6. Rohit Arondekar
    Rohit Arondekar

    Any updates on this ticket? Is output that Neeraj has shown acceptable?

    June 15th, 2010 @ 11:10 AM

  7. Rohit Arondekar
    Rohit Arondekar

    I fixed the formating of the comment made by Neeraj. Does this need more work or is the output acceptable?

    June 21st, 2010 @ 08:21 AM

  8. Neeraj Singh
    Neeraj Singh

    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.

    June 22nd, 2010 @ 11:43 AM

  9. Neeraj Singh
    Neeraj Singh
    • 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.

    July 1st, 2010 @ 04:18 AM

  10. Jeremy Kemper
    Jeremy Kemper
    • State changed from open to resolved

    Great!

    July 1st, 2010 @ 05:21 AM

  11. Ryan Bigg
    Ryan Bigg
    • Tag cleared.

    Automatic cleanup of spam.

    October 9th, 2010 @ 10:02 PM