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.

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

#6456

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')

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

State: new
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Ludo van den Boom
    Ludo van den Boom
    • 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

    February 20th, 2011 @ 12:32 PM