This project is archived and is in readonly mode.

#1587 ✓invalid
Conrad Taylor

model.to_xml does not generate all type attributes

Reported by Conrad Taylor | December 17th, 2008 @ 02:14 PM | in 2.x

I noticed the to_xml method does not generate type attributes for all the elements for a given model. For example,

Model:

<person> <created-at type="datetime">2008-08-16T17:28:19Z</created-at> <description>This is a test</description> <id type="integer">1</id> <name>Conrad</name> <updated-at type="datetime">2008-08-16T17:28:19Z</updated-at> </person>

Collection:

<people type="array"> <person>

<created-at type="datetime">2008-08-16T17:28:19Z</created-at>
<description>This is a test</description>
<id type="integer">1</id>
<name>Conrad</name>
<updated-at type="datetime">2008-08-16T17:28:19Z</updated-at>

<created-at type="datetime">2008-09-27T23:25:40Z</created-at>
<description>This is yet another test 2.</description>
<id type="integer">2</id>
<name>Conrad Taylor</name>
<updated-at type="datetime">2008-09-27T23:26:02Z</updated-at>

BTW, name is a "string" field and description is a "text" field. It appears that the :skip_type => false is the default behavior from the documentation.

Comments and changes to this ticket

  • Frederick Cheung

    Frederick Cheung December 18th, 2008 @ 12:38 AM

    What where you expecting ? and ?

  • Conrad Taylor

    Conrad Taylor December 20th, 2008 @ 04:10 AM

    I was expecting to see the following for the name and description elements:

    <people>

    <person>
    
      <description type="text" >This is a test</description>
    
      ...
    
      <name type="string">Conrad</name>
    
    </person>
    
    
    <description type="text">This is yet another test 2.</description>
    
    ...
    
    <name type="string">Conrad</name>
    
    
  • Frederick Cheung

    Frederick Cheung December 20th, 2008 @ 11:09 AM

    They're both just plain text data. the type atribute isn't supposed to replicate the database schema, ie you see integer not bigint(12) so that whatever is reading the xml knows how to interpret the plain text content. In the case where the content is just plain text we don't need to say anything.

  • Conrad Taylor

    Conrad Taylor December 20th, 2008 @ 12:51 PM

    OK, why do we have some type attributes for some elements and no type attributes for others? Next, the generated XML appears to simply display what's contained in the schema.rb file. The :skip_type option is set to false by default from reading the documentation. In any case, I was thinking about using this generated XML file with it's type attribute to populate a Gemstone/S database.

  • Frederick Cheung

    Frederick Cheung December 20th, 2008 @ 01:57 PM

    I believe the only type without attributes are the ones which are purely textual in nature (and if you look at the source this is quite deliberate). I know nothing about gemstone/S but when loading a record does it really care about whether the value came from a text column or a varchar column ?

  • Conrad Taylor

    Conrad Taylor December 20th, 2008 @ 02:59 PM

    Why even define the type attribute when generating XML? The type of an XML field can be determined or selected from an XML Schema.

  • Frederick Cheung

    Frederick Cheung December 21st, 2008 @ 10:58 AM

    That's why skip_types is there I suppose. On the other why not be helpful when there is no xsd / client doesn't support xsd/ you can't be bother with an xsd.

  • Conrad Taylor
  • Pratik

    Pratik January 18th, 2009 @ 05:50 AM

    • State changed from “new” to “invalid”

    Please reopen if this is an open issue.

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>

People watching this ticket

Pages