@@ -9,6 +9,7 @@ def self.type_for(serializer, serializer_type = nil, transform_options = {})
99
1010 def self . for_type_with_id ( type , id , options )
1111 return nil if id . blank?
12+ type = inflect_type ( type )
1213 {
1314 id : id . to_s ,
1415 type : type_for ( :no_class_needed , type , options )
@@ -17,13 +18,17 @@ def self.for_type_with_id(type, id, options)
1718
1819 def self . raw_type_from_serializer_object ( object )
1920 class_name = object . class . name # should use model_name
20- serializer_type = class_name . underscore
21+ raw_type = class_name . underscore
22+ raw_type = inflect_type ( raw_type )
23+ raw_type
24+ . gsub! ( '/' . freeze , ActiveModelSerializers . config . jsonapi_namespace_separator )
25+ raw_type
26+ end
27+
28+ def self . inflect_type ( type )
2129 singularize = ActiveModelSerializers . config . jsonapi_resource_type == :singular
2230 inflection = singularize ? :singularize : :pluralize
23- serializer_type = ActiveSupport ::Inflector . public_send ( inflection , serializer_type )
24- serializer_type
25- . gsub! ( '/' . freeze , ActiveModelSerializers . config . jsonapi_namespace_separator )
26- serializer_type
31+ ActiveSupport ::Inflector . public_send ( inflection , type )
2732 end
2833
2934 # {http://jsonapi.org/format/#document-resource-identifier-objects Resource Identifier Objects}
@@ -44,7 +49,8 @@ def as_json
4449 private
4550
4651 def type_for ( serializer , transform_options )
47- self . class . type_for ( serializer , serializer . _type , transform_options )
52+ serializer_type = serializer . _type
53+ self . class . type_for ( serializer , serializer_type , transform_options )
4854 end
4955
5056 def id_for ( serializer )
0 commit comments