aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model
diff options
context:
space:
mode:
authorSteve Klabnik <steve@steveklabnik.com>2012-10-05 15:07:39 -0600
committerSteve Klabnik <steve@steveklabnik.com>2012-11-28 11:48:32 -0800
commit9504b44cf60c1d69519cef32465f46a73719bc17 (patch)
treef3b5f0ae2c80cd9cf6e390a112f34d2f11e893fe /activemodel/lib/active_model
parent3e965e2144d515499c3c94de7973cf0bd84649e2 (diff)
downloadrails-9504b44cf60c1d69519cef32465f46a73719bc17.tar.gz
rails-9504b44cf60c1d69519cef32465f46a73719bc17.tar.bz2
rails-9504b44cf60c1d69519cef32465f46a73719bc17.zip
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
Diffstat (limited to 'activemodel/lib/active_model')
-rwxr-xr-xactivemodel/lib/active_model/serializers/xml.rb7
1 files changed, 6 insertions, 1 deletions
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