From ea3ff21672835dbc86ecbb88b723d2609d2b0232 Mon Sep 17 00:00:00 2001 From: Larry Gebhardt Date: Wed, 19 May 2021 16:49:06 -0400 Subject: [PATCH] Use underscore instead of downcase (#1366) Use underscore instead of downcase for polymorphic names --- lib/jsonapi/active_relation_resource.rb | 2 +- lib/jsonapi/basic_resource.rb | 4 ++-- lib/jsonapi/relationship.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/jsonapi/active_relation_resource.rb b/lib/jsonapi/active_relation_resource.rb index f968b8543..ed3b89d20 100644 --- a/lib/jsonapi/active_relation_resource.rb +++ b/lib/jsonapi/active_relation_resource.rb @@ -649,7 +649,7 @@ def find_related_polymorphic_fragments(source_rids, relationship, options, conne end end - relation_position = relation_positions[row[2].downcase.pluralize] + relation_position = relation_positions[row[2].underscore.pluralize] model_fields = relation_position[:model_fields] cache_field = relation_position[:cache_field] cache_offset = relation_position[:cache_offset] diff --git a/lib/jsonapi/basic_resource.rb b/lib/jsonapi/basic_resource.rb index 4713c548f..ecd6e4778 100644 --- a/lib/jsonapi/basic_resource.rb +++ b/lib/jsonapi/basic_resource.rb @@ -873,7 +873,7 @@ def _polymorphic_name if !_polymorphic '' else - @_polymorphic_name ||= _model_name.to_s.downcase + @_polymorphic_name ||= _model_name.to_s.underscore end end @@ -927,7 +927,7 @@ def _polymorphic_types next unless Module === klass if klass < ActiveRecord::Base klass.reflect_on_all_associations(:has_many).select{|r| r.options[:as] }.each do |reflection| - (hash[reflection.options[:as]] ||= []) << klass.name.downcase + (hash[reflection.options[:as]] ||= []) << klass.name.underscore end end end diff --git a/lib/jsonapi/relationship.rb b/lib/jsonapi/relationship.rb index 77e700b78..a185587c9 100644 --- a/lib/jsonapi/relationship.rb +++ b/lib/jsonapi/relationship.rb @@ -63,7 +63,7 @@ def self.polymorphic_types(name) next unless Module === klass if ActiveRecord::Base > klass klass.reflect_on_all_associations(:has_many).select{|r| r.options[:as] }.each do |reflection| - (hash[reflection.options[:as]] ||= []) << klass.name.downcase + (hash[reflection.options[:as]] ||= []) << klass.name.underscore end end end