adds polymorphic option to association definition which includes association type in serializer

regen gemlock

regen gemlock

better variable naming

rubocop fixes

adds to changelog

adds empty relationship and has_many polymorph tests

indent

test cleaning

-rubocop

rubocop

rubocop

rubocop

changelog

remove silly .DS

fix roque failure

fix
This commit is contained in:
cgmckeever
2016-05-15 13:19:37 -05:00
parent 6c321cd862
commit bbed12864d
6 changed files with 159 additions and 14 deletions

View File

@@ -45,7 +45,14 @@ module ActiveModelSerializers
return unless association.serializer && association.serializer.object
opts = instance_options.merge(include: @include_tree[association.key])
Attributes.new(association.serializer, opts).serializable_hash(options)
relationship_value = Attributes.new(association.serializer, opts).serializable_hash(options)
if association.options[:polymorphic] && relationship_value
polymorphic_type = association.serializer.object.class.name.underscore
relationship_value = { type: polymorphic_type, polymorphic_type.to_sym => relationship_value }
end
relationship_value
end
# Set @cached_attributes