From 411b610b86b2e23a0f20f9d8ccdc64e8ff0b80a1 Mon Sep 17 00:00:00 2001 From: Vivek Kumar Date: Wed, 11 Jul 2018 11:23:22 +0530 Subject: [PATCH] Fix wrong type for polymorphic association while deserialization while deserializing any polymorphic relation, the type of the record was coming wrong. (e.g, for a relation of type 'BlogPost', the type was coming out as 'Blog-post'). This was happening because, we were not converting the hyphenated 'type' to underscore. This PR will do that before calling classify on the type. --- .../adapter/json_api/deserialization.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_model_serializers/adapter/json_api/deserialization.rb b/lib/active_model_serializers/adapter/json_api/deserialization.rb index d846cacc4..0e8a203ab 100644 --- a/lib/active_model_serializers/adapter/json_api/deserialization.rb +++ b/lib/active_model_serializers/adapter/json_api/deserialization.rb @@ -189,7 +189,7 @@ def parse_relationship(assoc_name, assoc_data, options) polymorphic = (options[:polymorphic] || []).include?(assoc_name.to_sym) if polymorphic - hash["#{prefix_key}_type".to_sym] = assoc_data.present? ? assoc_data['type'].classify : nil + hash["#{prefix_key}_type".to_sym] = assoc_data.present? ? assoc_data['type'].underscore.classify : nil end hash