Add key option to serializer associations

This commit is contained in:
Rodrigo Ra
2015-07-05 19:47:58 -03:00
parent ac1991fd6b
commit df63b59512
8 changed files with 109 additions and 29 deletions

View File

@@ -15,23 +15,23 @@ module ActiveModel
serializer.attributes(options)
end
serializer.each_association do |name, association, opts|
serializer.each_association do |key, association, opts|
if association.respond_to?(:each)
array_serializer = association
@hash[name] = array_serializer.map do |item|
@hash[key] = array_serializer.map do |item|
cache_check(item) do
item.attributes(opts)
end
end
else
if association && association.object
@hash[name] = cache_check(association) do
@hash[key] = cache_check(association) do
association.attributes(options)
end
elsif opts[:virtual_value]
@hash[name] = opts[:virtual_value]
@hash[key] = opts[:virtual_value]
else
@hash[name] = nil
@hash[key] = nil
end
end
end