aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/xml_serialization.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/xml_serialization.rb')
-rw-r--r--activerecord/lib/active_record/xml_serialization.rb8
1 files changed, 6 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/xml_serialization.rb b/activerecord/lib/active_record/xml_serialization.rb
index 5f7a39d73b..42fe46bca3 100644
--- a/activerecord/lib/active_record/xml_serialization.rb
+++ b/activerecord/lib/active_record/xml_serialization.rb
@@ -207,8 +207,12 @@ module ActiveRecord #:nodoc:
records = @record.send(association).to_a
tag = association.to_s
tag = tag.dasherize if dasherize?
- builder.tag!(tag, :type => :array) do
- records.each { |r| r.to_xml(opts.merge(:root=>r.class.to_s.underscore)) }
+ if records.empty?
+ builder.tag!(tag, :type => :array)
+ else
+ builder.tag!(tag, :type => :array) do
+ records.each { |r| r.to_xml(opts.merge(:root=>r.class.to_s.underscore)) }
+ end
end
when :has_one, :belongs_to
if record = @record.send(association)