This project is archived and is in readonly mode.

#6456 new
Ludo van den Boom

[Patch] ActiveRecord's XmlSerializer should not singularize already singular association names

Reported by Ludo van den Boom | February 20th, 2011 @ 12:04 PM

The current to_xml behavior is incorrect. It singularizes already singular association names, resulting in xml that does not represent the original models/associations. Attached patch fixes this.

Steps to reproduce

Say we have the following models:

class Address < ActiveRecord::Base; belongs_to :person; end
class Person < ActiveRecord::Base; has_one :address; end

Now, in Rails console, find a Person and do:

> @person.to_xml(:skip_instruct => true, :include => :address)

Current to_xml result (Rails 3.0.4):

<person>
  <id type="integer">1</id>
  <addres>
    <id type="integer">1</id>
  </addres>
</person>

After applying patch:

<person>
  <id type="integer">1</id>
  <address>
    <id type="integer">1</id>
  </address>
</person>

(notice the difference in the spelling of 'address')

Comments and changes to this ticket

  • Ludo van den Boom

    Ludo van den Boom February 20th, 2011 @ 12:32 PM

    • Title changed from “ActiveRecord's XmlSerializer should not singularize already singular association names” to “[Patch] ActiveRecord's XmlSerializer should not singularize already singular association names”

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>

Attachments

Pages