mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
@@ -37,5 +37,27 @@ module ActiveModel
|
||||
end
|
||||
end
|
||||
alias_method :serializable_object, :serializable_array
|
||||
|
||||
def serializable_data
|
||||
embedded_in_root_associations.merge!(super)
|
||||
end
|
||||
|
||||
def embedded_in_root_associations
|
||||
hash = {}
|
||||
@object.map do |item|
|
||||
serializer_class = @each_serializer || Serializer.serializer_for(item) || DefaultSerializer
|
||||
associations = serializer_class._associations
|
||||
serializer = serializer_class.new(item, @options)
|
||||
included_associations = serializer.filter(associations.keys)
|
||||
associations.each do |(name, association)|
|
||||
if included_associations.include? name
|
||||
if association.embed_in_root?
|
||||
hash[association.embedded_key] = serializer.serialize association
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
hash
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user