Fix JSON:API polymorphic type regression from v0.10.5

This commit is contained in:
Benjamin Fleischer 2017-10-29 19:40:46 -05:00
parent 0fcb8a6cce
commit cf29db34c6

View File

@ -46,7 +46,14 @@ module ActiveModelSerializers
if association.belongs_to? && if association.belongs_to? &&
parent_serializer.object.respond_to?(association.reflection.foreign_key) parent_serializer.object.respond_to?(association.reflection.foreign_key)
id = parent_serializer.read_attribute_for_serialization(association.reflection.foreign_key) id = parent_serializer.read_attribute_for_serialization(association.reflection.foreign_key)
type = association.reflection.type.to_s if association.polymorphic?
# We can't infer resource type for polymorphic relationships from the serializer.
# We can ONLY know a polymorphic resource type by inspecting each resource.
serializer = association.lazy_association.serializer
type = serializer.json_key
else
type = association.reflection.type.to_s
end
ResourceIdentifier.for_type_with_id(type, id, serializable_resource_options) ResourceIdentifier.for_type_with_id(type, id, serializable_resource_options)
else else
# TODO(BF): Process relationship without evaluating lazy_association # TODO(BF): Process relationship without evaluating lazy_association