Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

to_xml with :include should skip_instruct on the included records [#4506

 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
commit 60504e62c8e2f5e137a0ac82aed67a6c0fe42447 1 parent a003a39
@lawrencepit lawrencepit authored josevalim committed
View
2  activerecord/lib/active_record/serializers/xml_serializer.rb
@@ -197,7 +197,7 @@ def add_includes
# TODO This can likely be cleaned up to simple use ActiveSupport::XmlMini.to_tag as well.
def add_associations(association, records, opts)
association_name = association.to_s.singularize
- merged_options = options.merge(opts).merge!(:root => association_name)
+ merged_options = options.merge(opts).merge!(:root => association_name, :skip_instruct => true)
if records.is_a?(Enumerable)
tag = ActiveSupport::XmlMini.rename_key(association.to_s, options)
View
7 activerecord/test/cases/serialization_test.rb
@@ -44,4 +44,11 @@ def test_serialize_should_allow_attribute_except_filtering
assert_equal @contact_attributes[:awesome], contact.awesome, "For #{format}"
end
end
+
+ def test_serialize_should_xml_skip_instruct_for_included_records
+ @contact.alternative = Contact.new(:name => 'Copa Cabana')
+ @serialized = @contact.to_xml(:include => [ :alternative ])
+ assert_equal @serialized.index('<?xml '), 0
+ assert_nil @serialized.index('<?xml ', 1)
+ end
end
View
4 activerecord/test/models/contact.rb
@@ -13,4 +13,6 @@ def self.column(name, sql_type = nil, options = {})
column :preferences, :string
serialize :preferences
-end
+
+ belongs_to :alternative, :class_name => 'Contact'
+end
Please sign in to comment.
Something went wrong with that request. Please try again.