jsonapi-resources 0.10.0 → 0.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jsonapi/active_relation_resource.rb +25 -11
- data/lib/jsonapi/resources/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb454d152ad0d4006c635c266ef12a4b5bc01d2d1f90768010545beb1c706509
|
4
|
+
data.tar.gz: 453cbec4004419cc4ed2f2cb9fd5b85879b6348dc1be033d44c19b8f7b6a74a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34d71bab88b0d790e160514373fda6d0328c405662995f9235663f648994f9e984f2f1327846e9713cb2777d66d4cc838401253cd842b96cc3485cf61e3cc776
|
7
|
+
data.tar.gz: e14d5b344c99beb03229c7f98800ea84de86fccc86fddb581df6341d210fc962669b83051a93c1ed4665c4019d5f76d96ca225844a4b0a53c34c212da08d656c
|
@@ -153,6 +153,11 @@ module JSONAPI
|
|
153
153
|
pluck_fields << Arel.sql("#{concat_table_field(resource_table_alias, model_field[:name])} AS #{resource_table_alias}_#{model_field[:name]}")
|
154
154
|
end
|
155
155
|
|
156
|
+
sort_fields = options.dig(:_relation_helper_options, :sort_fields)
|
157
|
+
sort_fields.try(:each) do |field|
|
158
|
+
pluck_fields << Arel.sql(field)
|
159
|
+
end
|
160
|
+
|
156
161
|
fragments = {}
|
157
162
|
rows = records.pluck(*pluck_fields)
|
158
163
|
rows.each do |row|
|
@@ -445,6 +450,11 @@ module JSONAPI
|
|
445
450
|
pluck_fields << Arel.sql("#{concat_table_field(resource_table_alias, model_field[:name])} AS #{resource_table_alias}_#{model_field[:name]}")
|
446
451
|
end
|
447
452
|
|
453
|
+
sort_fields = options.dig(:_relation_helper_options, :sort_fields)
|
454
|
+
sort_fields.try(:each) do |field|
|
455
|
+
pluck_fields << Arel.sql(field)
|
456
|
+
end
|
457
|
+
|
448
458
|
fragments = {}
|
449
459
|
rows = records.distinct.pluck(*pluck_fields)
|
450
460
|
rows.each do |row|
|
@@ -680,24 +690,23 @@ module JSONAPI
|
|
680
690
|
paginator: nil,
|
681
691
|
options: {})
|
682
692
|
|
683
|
-
|
684
|
-
|
693
|
+
options[:_relation_helper_options] = { join_manager: join_manager, sort_fields: [] }
|
694
|
+
|
695
|
+
records = resource_klass.apply_joins(records, join_manager, options)
|
685
696
|
|
686
697
|
if primary_keys
|
687
698
|
records = records.where(_primary_key => primary_keys)
|
688
699
|
end
|
689
700
|
|
690
|
-
opts[:join_manager] = join_manager
|
691
|
-
|
692
701
|
unless filters.empty?
|
693
|
-
records = resource_klass.filter_records(records, filters,
|
702
|
+
records = resource_klass.filter_records(records, filters, options)
|
694
703
|
end
|
695
704
|
|
696
705
|
if sort_primary
|
697
706
|
records = records.order(_primary_key => :asc)
|
698
707
|
else
|
699
708
|
order_options = resource_klass.construct_order_options(sort_criteria)
|
700
|
-
records = resource_klass.sort_records(records, order_options,
|
709
|
+
records = resource_klass.sort_records(records, order_options, options)
|
701
710
|
end
|
702
711
|
|
703
712
|
if paginator
|
@@ -731,12 +740,16 @@ module JSONAPI
|
|
731
740
|
|
732
741
|
strategy = _allowed_sort.fetch(field.to_sym, {})[:apply]
|
733
742
|
|
743
|
+
options[:_relation_helper_options] ||= {}
|
744
|
+
options[:_relation_helper_options][:sort_fields] ||= []
|
745
|
+
|
734
746
|
if strategy
|
735
747
|
records = call_method_or_proc(strategy, records, direction, context)
|
736
748
|
else
|
737
|
-
join_manager = options
|
738
|
-
|
739
|
-
|
749
|
+
join_manager = options.dig(:_relation_helper_options, :join_manager)
|
750
|
+
sort_field = join_manager ? get_aliased_field(field, join_manager) : field
|
751
|
+
options[:_relation_helper_options][:sort_fields].push("#{sort_field}")
|
752
|
+
records = records.order(Arel.sql("#{sort_field} #{direction}"))
|
740
753
|
end
|
741
754
|
records
|
742
755
|
end
|
@@ -825,8 +838,9 @@ module JSONAPI
|
|
825
838
|
if strategy
|
826
839
|
records = call_method_or_proc(strategy, records, value, options)
|
827
840
|
else
|
828
|
-
join_manager = options
|
829
|
-
|
841
|
+
join_manager = options.dig(:_relation_helper_options, :join_manager)
|
842
|
+
field = join_manager ? get_aliased_field(filter, join_manager) : filter
|
843
|
+
records = records.where(Arel.sql(field) => value)
|
830
844
|
end
|
831
845
|
|
832
846
|
records
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonapi-resources
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Gebhardt
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-
|
12
|
+
date: 2019-10-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -247,7 +247,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
247
247
|
- !ruby/object:Gem::Version
|
248
248
|
version: '0'
|
249
249
|
requirements: []
|
250
|
-
|
250
|
+
rubyforge_project:
|
251
|
+
rubygems_version: 2.7.6.2
|
251
252
|
signing_key:
|
252
253
|
specification_version: 4
|
253
254
|
summary: Easily support JSON API in Rails.
|