mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
This commit moves support for the :include serialization option for serializing associated objects out of ActiveRecord in into ActiveModel. The following methods support the :include option: * serializable_hash * to_json * to_xml Instances must respond to methods named by the values of the :includes array (or keys of the :includes hash). If an association method returns an object that is_a?(Enumerable) (which AR has_many associations do), it is assumed to be a collection association, and its elements must respond to :serializable_hash. Otherwise it must respond to :serializable_hash itself. While here, fix #858, XmlSerializer should not singularize already singular association names.
19 lines
481 B
Ruby
19 lines
481 B
Ruby
module ActiveRecord #:nodoc:
|
|
# = Active Record Serialization
|
|
module Serialization
|
|
extend ActiveSupport::Concern
|
|
include ActiveModel::Serializers::JSON
|
|
|
|
def serializable_hash(options = nil)
|
|
options = options.try(:clone) || {}
|
|
|
|
options[:except] = Array.wrap(options[:except]).map { |n| n.to_s }
|
|
options[:except] |= Array.wrap(self.class.inheritance_column)
|
|
|
|
super(options)
|
|
end
|
|
end
|
|
end
|
|
|
|
require 'active_record/serializers/xml_serializer'
|