diff options
author | Tobias Lütke <tobias.luetke@gmail.com> | 2007-07-09 22:07:39 +0000 |
---|---|---|
committer | Tobias Lütke <tobias.luetke@gmail.com> | 2007-07-09 22:07:39 +0000 |
commit | 187e1f85d0c871ba61e5bc3651a7ec2f657db8f9 (patch) | |
tree | c260f539da2ec6457aa732f3fb98c7926a80fe9f /activerecord/lib/active_record | |
parent | cb2381696029ad839ecddad08afea061d07685fb (diff) | |
download | rails-187e1f85d0c871ba61e5bc3651a7ec2f657db8f9.tar.gz rails-187e1f85d0c871ba61e5bc3651a7ec2f657db8f9.tar.bz2 rails-187e1f85d0c871ba61e5bc3651a7ec2f657db8f9.zip |
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
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/xml_serialization.rb | 12 |
1 files changed, 11 insertions, 1 deletions
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 |