From 187e1f85d0c871ba61e5bc3651a7ec2f657db8f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20L=C3=BCtke?= Date: Mon, 9 Jul 2007 22:07:39 +0000 Subject: Support for non heterogeneous arrays when serializing to xml. Unless guessable from array name the type name will be included as attribute git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7173 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/lib/active_record/xml_serialization.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/xml_serialization.rb b/activerecord/lib/active_record/xml_serialization.rb index 42fe46bca3..7e2d5dd01e 100644 --- a/activerecord/lib/active_record/xml_serialization.rb +++ b/activerecord/lib/active_record/xml_serialization.rb @@ -211,7 +211,13 @@ module ActiveRecord #:nodoc: 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)) } + 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) + ) + end end end when :has_one, :belongs_to @@ -247,6 +253,10 @@ module ActiveRecord #:nodoc: if options[:namespace] args << {:xmlns=>options[:namespace]} end + + if options[:type] + args << {:type=>options[:type]} + end builder.tag!(*args) do add_attributes -- cgit v1.2.3