Skip to content

Commit

Permalink
Use underscore instead of downcase (#1366)
Browse files Browse the repository at this point in the history
Use underscore instead of downcase for polymorphic names
  • Loading branch information
lgebhardt authored May 19, 2021
1 parent 2c853dd commit ea3ff21
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/jsonapi/active_relation_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions lib/jsonapi/basic_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/jsonapi/relationship.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ea3ff21

Please sign in to comment.