mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Adjusts JsonApi adapter to serialize attributes in a nested attributes hash
This commit is contained in:
@@ -85,26 +85,31 @@ module ActiveModel
|
||||
if serializer.respond_to?(:each)
|
||||
result = []
|
||||
serializer.each do |object|
|
||||
options[:fields] = @fieldset && @fieldset.fields_for(serializer)
|
||||
result << cache_check(object) do
|
||||
options[:required_fields] = [:id, :type]
|
||||
attributes = object.attributes(options)
|
||||
attributes[:id] = attributes[:id].to_s
|
||||
result << attributes
|
||||
end
|
||||
result << resource_object_for(object, options)
|
||||
end
|
||||
else
|
||||
options[:fields] = @fieldset && @fieldset.fields_for(serializer)
|
||||
options[:required_fields] = [:id, :type]
|
||||
result = cache_check(serializer) do
|
||||
result = serializer.attributes(options)
|
||||
result[:id] = result[:id].to_s
|
||||
result
|
||||
end
|
||||
result = resource_object_for(serializer, options)
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
def resource_object_for(serializer, options)
|
||||
options[:fields] = @fieldset && @fieldset.fields_for(serializer)
|
||||
options[:required_fields] = [:id, :type]
|
||||
|
||||
cache_check(serializer) do
|
||||
attributes = serializer.attributes(options)
|
||||
|
||||
result = {
|
||||
id: attributes.delete(:id).to_s,
|
||||
type: attributes.delete(:type)
|
||||
}
|
||||
|
||||
result[:attributes] = attributes if attributes.any?
|
||||
result
|
||||
end
|
||||
end
|
||||
|
||||
def include_assoc?(assoc)
|
||||
return false unless @options[:include]
|
||||
check_assoc("#{assoc}$")
|
||||
|
||||
Reference in New Issue
Block a user