aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorBruce Krysiak <bruce@socialpl.us>2009-03-10 11:17:16 +0000
committerPratik Naik <pratiknaik@gmail.com>2009-03-10 11:17:16 +0000
commit8272630ce8af0546e7d1aa9211a9d91b80700cbd (patch)
treebd1a2bda94fc7925480edfeefa003d22b5e5143a /activerecord/lib/active_record
parent0c9bbf8c9dca46fbd7916640c417d13bf8b5af30 (diff)
downloadrails-8272630ce8af0546e7d1aa9211a9d91b80700cbd.tar.gz
rails-8272630ce8af0546e7d1aa9211a9d91b80700cbd.tar.bz2
rails-8272630ce8af0546e7d1aa9211a9d91b80700cbd.zip
Ensure ActiveRecord#to_xml respects :skip_types for included associations [#1632 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/serializers/xml_serializer.rb18
1 files changed, 12 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/serializers/xml_serializer.rb b/activerecord/lib/active_record/serializers/xml_serializer.rb
index 4749823b94..fa75874603 100644
--- a/activerecord/lib/active_record/serializers/xml_serializer.rb
+++ b/activerecord/lib/active_record/serializers/xml_serializer.rb
@@ -231,16 +231,22 @@ module ActiveRecord #:nodoc:
def add_associations(association, records, opts)
if records.is_a?(Enumerable)
tag = reformat_name(association.to_s)
+ type = options[:skip_types] ? {} : {:type => "array"}
+
if records.empty?
- builder.tag!(tag, :type => :array)
+ builder.tag!(tag, type)
else
- builder.tag!(tag, :type => :array) do
+ builder.tag!(tag, type) do
association_name = association.to_s.singularize
records.each do |record|
- record.to_xml opts.merge(
- :root => association_name,
- :type => (record.class.to_s.underscore == association_name ? nil : record.class.name)
- )
+ if options[:skip_types]
+ record_type = {}
+ else
+ record_class = (record.class.to_s.underscore == association_name) ? nil : record.class.name
+ record_type = {:type => record_class}
+ end
+
+ record.to_xml opts.merge(:root => association_name).merge(record_type)
end
end
end