From 9504b44cf60c1d69519cef32465f46a73719bc17 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Fri, 5 Oct 2012 15:07:39 -0600 Subject: Specify type of singular association during serialization When serialising a class, specify the type of any singular associations, if necessary. Rails already correctly specifies the :type of any enumerable association (e.g. a has_many association), but made no attempt to do so for non-enumerables (e.g. a has_one association). We must specify the :type of any STI association. A has_one association to a class which uses single-table inheritance is an example of this type of association. Fixes #7471 --- activemodel/lib/active_model/serializers/xml.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'activemodel/lib') diff --git a/activemodel/lib/active_model/serializers/xml.rb b/activemodel/lib/active_model/serializers/xml.rb index fb6093cce5..4a17a63e20 100755 --- a/activemodel/lib/active_model/serializers/xml.rb +++ b/activemodel/lib/active_model/serializers/xml.rb @@ -149,7 +149,12 @@ module ActiveModel end else merged_options[:root] = association.to_s - records.to_xml(merged_options) + + unless records.class.to_s.underscore == association.to_s + merged_options[:type] = records.class.name + end + + records.to_xml merged_options end end -- cgit v1.2.3