class ActiveModel::Serializer::Reflection

def build_association(subject, parent_serializer_options)

Other tags:
    Api: - private

Parameters:
  • parent_serializer_options (Hash{Symbol => Object}) --
  • subject (Serializer) -- is a parent serializer for given association
def build_association(subject, parent_serializer_options)
  association_value = value(subject)
  reflection_options = options.dup
  serializer_class = subject.class.serializer_for(association_value, reflection_options)
  reflection_options[:include_data] = @_include_data
  if serializer_class
    begin
      serializer = serializer_class.new(
        association_value,
        serializer_options(subject, parent_serializer_options, reflection_options)
      )
    rescue ActiveModel::Serializer::CollectionSerializer::NoSerializerError
      reflection_options[:virtual_value] = association_value.try(:as_json) || association_value
    end
  elsif !association_value.nil? && !association_value.instance_of?(Object)
    reflection_options[:virtual_value] = association_value
  end
  Association.new(name, serializer, reflection_options, @_links, @_meta)
end