mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
First try to implement ArraySerializer
This commit is contained in:
@@ -3,20 +3,21 @@ module ActiveModel
|
||||
class Adapter
|
||||
class JsonApiAdapter < Adapter
|
||||
def serializable_hash(options = {})
|
||||
hash = serializer.attributes.each_with_object({}) do |(attr, value), h|
|
||||
h[attr] = value
|
||||
end
|
||||
hash = serializer.attributes
|
||||
|
||||
serializer.associations(only: [:id]).each_with_object({}) do |(attr, value), h|
|
||||
case value
|
||||
when ActiveModel::Serializer::ArraySerializer
|
||||
# process has_many association
|
||||
when ActiveModel::Serializer
|
||||
# process belongs_to association
|
||||
else
|
||||
# what?
|
||||
end
|
||||
associations = serializer.associations(only: [:id]).each_with_object({}) do |(attr, value), h|
|
||||
h[attr] = case value
|
||||
when ActiveModel::Serializer::ArraySerializer
|
||||
value.attributes(options).map do |item|
|
||||
item.id
|
||||
end.to_a
|
||||
when ActiveModel::Serializer
|
||||
# process belongs_to association
|
||||
else
|
||||
# what?
|
||||
end
|
||||
end
|
||||
hash.merge(associations)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user