lib/jsonapi/basic_resource.rb in jsonapi-resources-0.10.4 vs lib/jsonapi/basic_resource.rb in jsonapi-resources-0.10.5
- old
+ new
@@ -871,11 +871,11 @@
def _polymorphic_name
if !_polymorphic
''
else
- @_polymorphic_name ||= _model_name.to_s.downcase
+ @_polymorphic_name ||= _model_name.to_s.underscore
end
end
def _primary_key
@_primary_key ||= _default_primary_key
@@ -925,11 +925,11 @@
@poly_hash ||= {}.tap do |hash|
ObjectSpace.each_object do |klass|
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
end
@poly_hash[_polymorphic_name.to_sym]
@@ -1056,10 +1056,10 @@
def default_sort
[{field: 'id', direction: :asc}]
end
def construct_order_options(sort_params)
- sort_params ||= default_sort
+ sort_params = default_sort if sort_params.blank?
return {} unless sort_params
sort_params.each_with_object({}) do |sort, order_hash|
field = sort[:field].to_s == 'id' ? _primary_key : sort[:field].to_s