From 8b173f3bc5484a33ab985fd1a556f1f744e82cd7 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Fri, 22 Jun 2012 00:27:00 -0300 Subject: Fix serializable_hash with xml generation and default :except option When generating xml with a custom implementation of serializable_hash, if using the :except option, it was being overriden by the default AR implementation that attempts to ignore the inheritance column from STI automatically. So, if you have an implementation like this: def serializable_hash(options={}) super({ except: %w(some_attr) }.merge!(options)) end The :except option was correctly being used for :json generation, but not for :xml, because the options hash already contained the :except key with the inheritance column, thus overriding the customization. This commit fixes this problem by removing the :except logic from the xml serializer, that happened before calling serializable_hash. Since serializable_hash also does the same check for inheritance column, this logic was duplicated in both places, thus it's safe to remove it from xml serializer (see ActiveRecord::Serialization#serializable_hash). This is an attempt to solve issue #2498, that claims for a "Single transformation API for both xml and json representations". --- activerecord/lib/active_record/serializers/xml_serializer.rb | 5 ----- 1 file changed, 5 deletions(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/serializers/xml_serializer.rb b/activerecord/lib/active_record/serializers/xml_serializer.rb index b833af64fe..834d01a1e8 100644 --- a/activerecord/lib/active_record/serializers/xml_serializer.rb +++ b/activerecord/lib/active_record/serializers/xml_serializer.rb @@ -177,11 +177,6 @@ module ActiveRecord #:nodoc: end class XmlSerializer < ActiveModel::Serializers::Xml::Serializer #:nodoc: - def initialize(*args) - super - options[:except] = Array(options[:except]) | Array(@serializable.class.inheritance_column) - end - class Attribute < ActiveModel::Serializers::Xml::Serializer::Attribute #:nodoc: def compute_type klass = @serializable.class -- cgit v1.2.3