Skip to content

Commit ea3ff21

Browse files
authored
Use underscore instead of downcase (#1366)
Use underscore instead of downcase for polymorphic names
1 parent 2c853dd commit ea3ff21

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

lib/jsonapi/active_relation_resource.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ def find_related_polymorphic_fragments(source_rids, relationship, options, conne
649649
end
650650
end
651651

652-
relation_position = relation_positions[row[2].downcase.pluralize]
652+
relation_position = relation_positions[row[2].underscore.pluralize]
653653
model_fields = relation_position[:model_fields]
654654
cache_field = relation_position[:cache_field]
655655
cache_offset = relation_position[:cache_offset]

lib/jsonapi/basic_resource.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,7 @@ def _polymorphic_name
873873
if !_polymorphic
874874
''
875875
else
876-
@_polymorphic_name ||= _model_name.to_s.downcase
876+
@_polymorphic_name ||= _model_name.to_s.underscore
877877
end
878878
end
879879

@@ -927,7 +927,7 @@ def _polymorphic_types
927927
next unless Module === klass
928928
if klass < ActiveRecord::Base
929929
klass.reflect_on_all_associations(:has_many).select{|r| r.options[:as] }.each do |reflection|
930-
(hash[reflection.options[:as]] ||= []) << klass.name.downcase
930+
(hash[reflection.options[:as]] ||= []) << klass.name.underscore
931931
end
932932
end
933933
end

lib/jsonapi/relationship.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def self.polymorphic_types(name)
6363
next unless Module === klass
6464
if ActiveRecord::Base > klass
6565
klass.reflect_on_all_associations(:has_many).select{|r| r.options[:as] }.each do |reflection|
66-
(hash[reflection.options[:as]] ||= []) << klass.name.downcase
66+
(hash[reflection.options[:as]] ||= []) << klass.name.underscore
6767
end
6868
end
6969
end

0 commit comments

Comments
 (0)