nested_select 0.4.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,253 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ nested_select (0.4.4)
5
+ activerecord (>= 7)
6
+ activesupport (>= 7)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actioncable (7.2.2.1)
12
+ actionpack (= 7.2.2.1)
13
+ activesupport (= 7.2.2.1)
14
+ nio4r (~> 2.0)
15
+ websocket-driver (>= 0.6.1)
16
+ zeitwerk (~> 2.6)
17
+ actionmailbox (7.2.2.1)
18
+ actionpack (= 7.2.2.1)
19
+ activejob (= 7.2.2.1)
20
+ activerecord (= 7.2.2.1)
21
+ activestorage (= 7.2.2.1)
22
+ activesupport (= 7.2.2.1)
23
+ mail (>= 2.8.0)
24
+ actionmailer (7.2.2.1)
25
+ actionpack (= 7.2.2.1)
26
+ actionview (= 7.2.2.1)
27
+ activejob (= 7.2.2.1)
28
+ activesupport (= 7.2.2.1)
29
+ mail (>= 2.8.0)
30
+ rails-dom-testing (~> 2.2)
31
+ actionpack (7.2.2.1)
32
+ actionview (= 7.2.2.1)
33
+ activesupport (= 7.2.2.1)
34
+ nokogiri (>= 1.8.5)
35
+ racc
36
+ rack (>= 2.2.4, < 3.2)
37
+ rack-session (>= 1.0.1)
38
+ rack-test (>= 0.6.3)
39
+ rails-dom-testing (~> 2.2)
40
+ rails-html-sanitizer (~> 1.6)
41
+ useragent (~> 0.16)
42
+ actiontext (7.2.2.1)
43
+ actionpack (= 7.2.2.1)
44
+ activerecord (= 7.2.2.1)
45
+ activestorage (= 7.2.2.1)
46
+ activesupport (= 7.2.2.1)
47
+ globalid (>= 0.6.0)
48
+ nokogiri (>= 1.8.5)
49
+ actionview (7.2.2.1)
50
+ activesupport (= 7.2.2.1)
51
+ builder (~> 3.1)
52
+ erubi (~> 1.11)
53
+ rails-dom-testing (~> 2.2)
54
+ rails-html-sanitizer (~> 1.6)
55
+ activejob (7.2.2.1)
56
+ activesupport (= 7.2.2.1)
57
+ globalid (>= 0.3.6)
58
+ activemodel (7.2.2.1)
59
+ activesupport (= 7.2.2.1)
60
+ activerecord (7.2.2.1)
61
+ activemodel (= 7.2.2.1)
62
+ activesupport (= 7.2.2.1)
63
+ timeout (>= 0.4.0)
64
+ activestorage (7.2.2.1)
65
+ actionpack (= 7.2.2.1)
66
+ activejob (= 7.2.2.1)
67
+ activerecord (= 7.2.2.1)
68
+ activesupport (= 7.2.2.1)
69
+ marcel (~> 1.0)
70
+ activesupport (7.2.2.1)
71
+ base64
72
+ benchmark (>= 0.3)
73
+ bigdecimal
74
+ concurrent-ruby (~> 1.0, >= 1.3.1)
75
+ connection_pool (>= 2.2.5)
76
+ drb
77
+ i18n (>= 1.6, < 2)
78
+ logger (>= 1.4.2)
79
+ minitest (>= 5.1)
80
+ securerandom (>= 0.3)
81
+ tzinfo (~> 2.0, >= 2.0.5)
82
+ amazing_print (1.7.2)
83
+ appraisal (2.5.0)
84
+ bundler
85
+ rake
86
+ thor (>= 0.14.0)
87
+ ast (2.4.3)
88
+ base64 (0.2.0)
89
+ benchmark (0.4.0)
90
+ bigdecimal (3.1.9)
91
+ builder (3.3.0)
92
+ byebug (12.0.0)
93
+ concurrent-ruby (1.3.5)
94
+ connection_pool (2.5.3)
95
+ crass (1.0.6)
96
+ date (3.4.1)
97
+ drb (2.2.1)
98
+ erubi (1.13.1)
99
+ globalid (1.2.1)
100
+ activesupport (>= 6.1)
101
+ i18n (1.14.7)
102
+ concurrent-ruby (~> 1.0)
103
+ io-console (0.8.0)
104
+ irb (1.15.2)
105
+ pp (>= 0.6.0)
106
+ rdoc (>= 4.0.0)
107
+ reline (>= 0.4.2)
108
+ json (2.11.3)
109
+ language_server-protocol (3.17.0.4)
110
+ lint_roller (1.1.0)
111
+ logger (1.7.0)
112
+ loofah (2.24.0)
113
+ crass (~> 1.0.2)
114
+ nokogiri (>= 1.12.0)
115
+ mail (2.8.1)
116
+ mini_mime (>= 0.1.1)
117
+ net-imap
118
+ net-pop
119
+ net-smtp
120
+ marcel (1.0.4)
121
+ mini_mime (1.1.5)
122
+ minitest (5.25.5)
123
+ net-imap (0.5.8)
124
+ date
125
+ net-protocol
126
+ net-pop (0.1.2)
127
+ net-protocol
128
+ net-protocol (0.2.2)
129
+ timeout
130
+ net-smtp (0.5.1)
131
+ net-protocol
132
+ niceql (0.6.1)
133
+ nio4r (2.7.4)
134
+ nokogiri (1.18.8-x86_64-linux-gnu)
135
+ racc (~> 1.4)
136
+ parallel (1.27.0)
137
+ parser (3.3.8.0)
138
+ ast (~> 2.4.1)
139
+ racc
140
+ pp (0.6.2)
141
+ prettyprint
142
+ prettyprint (0.2.0)
143
+ prism (1.4.0)
144
+ psych (5.2.4)
145
+ date
146
+ stringio
147
+ racc (1.8.1)
148
+ rack (3.1.13)
149
+ rack-session (2.1.0)
150
+ base64 (>= 0.1.0)
151
+ rack (>= 3.0.0)
152
+ rack-test (2.2.0)
153
+ rack (>= 1.3)
154
+ rackup (2.2.1)
155
+ rack (>= 3)
156
+ rails (7.2.2.1)
157
+ actioncable (= 7.2.2.1)
158
+ actionmailbox (= 7.2.2.1)
159
+ actionmailer (= 7.2.2.1)
160
+ actionpack (= 7.2.2.1)
161
+ actiontext (= 7.2.2.1)
162
+ actionview (= 7.2.2.1)
163
+ activejob (= 7.2.2.1)
164
+ activemodel (= 7.2.2.1)
165
+ activerecord (= 7.2.2.1)
166
+ activestorage (= 7.2.2.1)
167
+ activesupport (= 7.2.2.1)
168
+ bundler (>= 1.15.0)
169
+ railties (= 7.2.2.1)
170
+ rails-dom-testing (2.2.0)
171
+ activesupport (>= 5.0.0)
172
+ minitest
173
+ nokogiri (>= 1.6)
174
+ rails-html-sanitizer (1.6.2)
175
+ loofah (~> 2.21)
176
+ nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
177
+ rails-i18n (7.0.10)
178
+ i18n (>= 0.7, < 2)
179
+ railties (>= 6.0.0, < 8)
180
+ rails_sql_prettifier (7.0.7)
181
+ activerecord (>= 7)
182
+ niceql (~> 0.6)
183
+ railties (7.2.2.1)
184
+ actionpack (= 7.2.2.1)
185
+ activesupport (= 7.2.2.1)
186
+ irb (~> 1.13)
187
+ rackup (>= 1.0.0)
188
+ rake (>= 12.2)
189
+ thor (~> 1.0, >= 1.2.2)
190
+ zeitwerk (~> 2.6)
191
+ rainbow (3.1.1)
192
+ rake (13.2.1)
193
+ rdoc (6.13.1)
194
+ psych (>= 4.0.0)
195
+ regexp_parser (2.10.0)
196
+ reline (0.6.1)
197
+ io-console (~> 0.5)
198
+ rubocop (1.75.4)
199
+ json (~> 2.3)
200
+ language_server-protocol (~> 3.17.0.2)
201
+ lint_roller (~> 1.1.0)
202
+ parallel (~> 1.10)
203
+ parser (>= 3.3.0.2)
204
+ rainbow (>= 2.2.2, < 4.0)
205
+ regexp_parser (>= 2.9.3, < 3.0)
206
+ rubocop-ast (>= 1.44.0, < 2.0)
207
+ ruby-progressbar (~> 1.7)
208
+ unicode-display_width (>= 2.4.0, < 4.0)
209
+ rubocop-ast (1.44.1)
210
+ parser (>= 3.3.7.2)
211
+ prism (~> 1.4)
212
+ rubocop-shopify (2.17.0)
213
+ rubocop (~> 1.62)
214
+ ruby-progressbar (1.13.0)
215
+ securerandom (0.4.1)
216
+ sqlite3 (2.6.0-x86_64-linux-gnu)
217
+ stringio (3.1.7)
218
+ stubberry (0.3.0)
219
+ thor (1.3.2)
220
+ timeout (0.4.3)
221
+ tzinfo (2.0.6)
222
+ concurrent-ruby (~> 1.0)
223
+ unicode-display_width (3.1.4)
224
+ unicode-emoji (~> 4.0, >= 4.0.4)
225
+ unicode-emoji (4.0.4)
226
+ useragent (0.16.11)
227
+ websocket-driver (0.7.7)
228
+ base64
229
+ websocket-extensions (>= 0.1.0)
230
+ websocket-extensions (0.1.5)
231
+ zeitwerk (2.7.2)
232
+
233
+ PLATFORMS
234
+ x86_64-linux-gnu
235
+
236
+ DEPENDENCIES
237
+ amazing_print
238
+ appraisal
239
+ bundler (>= 1.11)
240
+ byebug
241
+ minitest (~> 5.16)
242
+ nested_select!
243
+ rails (~> 7.2.0)
244
+ rails-i18n (>= 4)
245
+ rails_sql_prettifier
246
+ rake (~> 13.0)
247
+ rubocop (~> 1.21)
248
+ rubocop-shopify
249
+ sqlite3
250
+ stubberry
251
+
252
+ BUNDLED WITH
253
+ 2.5.11
@@ -0,0 +1,10 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rake", "~> 13.0"
6
+ gem "minitest", "~> 5.16"
7
+ gem "rubocop", "~> 1.21"
8
+ gem "rails", ">= 8"
9
+
10
+ gemspec path: "../"
@@ -0,0 +1,254 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ nested_select (0.4.4)
5
+ activerecord (>= 7)
6
+ activesupport (>= 7)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actioncable (8.0.2)
12
+ actionpack (= 8.0.2)
13
+ activesupport (= 8.0.2)
14
+ nio4r (~> 2.0)
15
+ websocket-driver (>= 0.6.1)
16
+ zeitwerk (~> 2.6)
17
+ actionmailbox (8.0.2)
18
+ actionpack (= 8.0.2)
19
+ activejob (= 8.0.2)
20
+ activerecord (= 8.0.2)
21
+ activestorage (= 8.0.2)
22
+ activesupport (= 8.0.2)
23
+ mail (>= 2.8.0)
24
+ actionmailer (8.0.2)
25
+ actionpack (= 8.0.2)
26
+ actionview (= 8.0.2)
27
+ activejob (= 8.0.2)
28
+ activesupport (= 8.0.2)
29
+ mail (>= 2.8.0)
30
+ rails-dom-testing (~> 2.2)
31
+ actionpack (8.0.2)
32
+ actionview (= 8.0.2)
33
+ activesupport (= 8.0.2)
34
+ nokogiri (>= 1.8.5)
35
+ rack (>= 2.2.4)
36
+ rack-session (>= 1.0.1)
37
+ rack-test (>= 0.6.3)
38
+ rails-dom-testing (~> 2.2)
39
+ rails-html-sanitizer (~> 1.6)
40
+ useragent (~> 0.16)
41
+ actiontext (8.0.2)
42
+ actionpack (= 8.0.2)
43
+ activerecord (= 8.0.2)
44
+ activestorage (= 8.0.2)
45
+ activesupport (= 8.0.2)
46
+ globalid (>= 0.6.0)
47
+ nokogiri (>= 1.8.5)
48
+ actionview (8.0.2)
49
+ activesupport (= 8.0.2)
50
+ builder (~> 3.1)
51
+ erubi (~> 1.11)
52
+ rails-dom-testing (~> 2.2)
53
+ rails-html-sanitizer (~> 1.6)
54
+ activejob (8.0.2)
55
+ activesupport (= 8.0.2)
56
+ globalid (>= 0.3.6)
57
+ activemodel (8.0.2)
58
+ activesupport (= 8.0.2)
59
+ activerecord (8.0.2)
60
+ activemodel (= 8.0.2)
61
+ activesupport (= 8.0.2)
62
+ timeout (>= 0.4.0)
63
+ activestorage (8.0.2)
64
+ actionpack (= 8.0.2)
65
+ activejob (= 8.0.2)
66
+ activerecord (= 8.0.2)
67
+ activesupport (= 8.0.2)
68
+ marcel (~> 1.0)
69
+ activesupport (8.0.2)
70
+ base64
71
+ benchmark (>= 0.3)
72
+ bigdecimal
73
+ concurrent-ruby (~> 1.0, >= 1.3.1)
74
+ connection_pool (>= 2.2.5)
75
+ drb
76
+ i18n (>= 1.6, < 2)
77
+ logger (>= 1.4.2)
78
+ minitest (>= 5.1)
79
+ securerandom (>= 0.3)
80
+ tzinfo (~> 2.0, >= 2.0.5)
81
+ uri (>= 0.13.1)
82
+ amazing_print (1.7.2)
83
+ appraisal (2.5.0)
84
+ bundler
85
+ rake
86
+ thor (>= 0.14.0)
87
+ ast (2.4.3)
88
+ base64 (0.2.0)
89
+ benchmark (0.4.0)
90
+ bigdecimal (3.1.9)
91
+ builder (3.3.0)
92
+ byebug (12.0.0)
93
+ concurrent-ruby (1.3.5)
94
+ connection_pool (2.5.3)
95
+ crass (1.0.6)
96
+ date (3.4.1)
97
+ drb (2.2.1)
98
+ erubi (1.13.1)
99
+ globalid (1.2.1)
100
+ activesupport (>= 6.1)
101
+ i18n (1.14.7)
102
+ concurrent-ruby (~> 1.0)
103
+ io-console (0.8.0)
104
+ irb (1.15.2)
105
+ pp (>= 0.6.0)
106
+ rdoc (>= 4.0.0)
107
+ reline (>= 0.4.2)
108
+ json (2.11.3)
109
+ language_server-protocol (3.17.0.4)
110
+ lint_roller (1.1.0)
111
+ logger (1.7.0)
112
+ loofah (2.24.0)
113
+ crass (~> 1.0.2)
114
+ nokogiri (>= 1.12.0)
115
+ mail (2.8.1)
116
+ mini_mime (>= 0.1.1)
117
+ net-imap
118
+ net-pop
119
+ net-smtp
120
+ marcel (1.0.4)
121
+ mini_mime (1.1.5)
122
+ minitest (5.25.5)
123
+ net-imap (0.5.8)
124
+ date
125
+ net-protocol
126
+ net-pop (0.1.2)
127
+ net-protocol
128
+ net-protocol (0.2.2)
129
+ timeout
130
+ net-smtp (0.5.1)
131
+ net-protocol
132
+ niceql (0.6.1)
133
+ nio4r (2.7.4)
134
+ nokogiri (1.18.8-x86_64-linux-gnu)
135
+ racc (~> 1.4)
136
+ parallel (1.27.0)
137
+ parser (3.3.8.0)
138
+ ast (~> 2.4.1)
139
+ racc
140
+ pp (0.6.2)
141
+ prettyprint
142
+ prettyprint (0.2.0)
143
+ prism (1.4.0)
144
+ psych (5.2.4)
145
+ date
146
+ stringio
147
+ racc (1.8.1)
148
+ rack (3.1.13)
149
+ rack-session (2.1.0)
150
+ base64 (>= 0.1.0)
151
+ rack (>= 3.0.0)
152
+ rack-test (2.2.0)
153
+ rack (>= 1.3)
154
+ rackup (2.2.1)
155
+ rack (>= 3)
156
+ rails (8.0.2)
157
+ actioncable (= 8.0.2)
158
+ actionmailbox (= 8.0.2)
159
+ actionmailer (= 8.0.2)
160
+ actionpack (= 8.0.2)
161
+ actiontext (= 8.0.2)
162
+ actionview (= 8.0.2)
163
+ activejob (= 8.0.2)
164
+ activemodel (= 8.0.2)
165
+ activerecord (= 8.0.2)
166
+ activestorage (= 8.0.2)
167
+ activesupport (= 8.0.2)
168
+ bundler (>= 1.15.0)
169
+ railties (= 8.0.2)
170
+ rails-dom-testing (2.2.0)
171
+ activesupport (>= 5.0.0)
172
+ minitest
173
+ nokogiri (>= 1.6)
174
+ rails-html-sanitizer (1.6.2)
175
+ loofah (~> 2.21)
176
+ nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
177
+ rails-i18n (8.0.1)
178
+ i18n (>= 0.7, < 2)
179
+ railties (>= 8.0.0, < 9)
180
+ rails_sql_prettifier (7.0.7)
181
+ activerecord (>= 7)
182
+ niceql (~> 0.6)
183
+ railties (8.0.2)
184
+ actionpack (= 8.0.2)
185
+ activesupport (= 8.0.2)
186
+ irb (~> 1.13)
187
+ rackup (>= 1.0.0)
188
+ rake (>= 12.2)
189
+ thor (~> 1.0, >= 1.2.2)
190
+ zeitwerk (~> 2.6)
191
+ rainbow (3.1.1)
192
+ rake (13.2.1)
193
+ rdoc (6.13.1)
194
+ psych (>= 4.0.0)
195
+ regexp_parser (2.10.0)
196
+ reline (0.6.1)
197
+ io-console (~> 0.5)
198
+ rubocop (1.75.4)
199
+ json (~> 2.3)
200
+ language_server-protocol (~> 3.17.0.2)
201
+ lint_roller (~> 1.1.0)
202
+ parallel (~> 1.10)
203
+ parser (>= 3.3.0.2)
204
+ rainbow (>= 2.2.2, < 4.0)
205
+ regexp_parser (>= 2.9.3, < 3.0)
206
+ rubocop-ast (>= 1.44.0, < 2.0)
207
+ ruby-progressbar (~> 1.7)
208
+ unicode-display_width (>= 2.4.0, < 4.0)
209
+ rubocop-ast (1.44.1)
210
+ parser (>= 3.3.7.2)
211
+ prism (~> 1.4)
212
+ rubocop-shopify (2.17.0)
213
+ rubocop (~> 1.62)
214
+ ruby-progressbar (1.13.0)
215
+ securerandom (0.4.1)
216
+ sqlite3 (2.6.0-x86_64-linux-gnu)
217
+ stringio (3.1.7)
218
+ stubberry (0.3.0)
219
+ thor (1.3.2)
220
+ timeout (0.4.3)
221
+ tzinfo (2.0.6)
222
+ concurrent-ruby (~> 1.0)
223
+ unicode-display_width (3.1.4)
224
+ unicode-emoji (~> 4.0, >= 4.0.4)
225
+ unicode-emoji (4.0.4)
226
+ uri (1.0.3)
227
+ useragent (0.16.11)
228
+ websocket-driver (0.7.7)
229
+ base64
230
+ websocket-extensions (>= 0.1.0)
231
+ websocket-extensions (0.1.5)
232
+ zeitwerk (2.7.2)
233
+
234
+ PLATFORMS
235
+ x86_64-linux-gnu
236
+
237
+ DEPENDENCIES
238
+ amazing_print
239
+ appraisal
240
+ bundler (>= 1.11)
241
+ byebug
242
+ minitest (~> 5.16)
243
+ nested_select!
244
+ rails (>= 8)
245
+ rails-i18n (>= 4)
246
+ rails_sql_prettifier
247
+ rake (~> 13.0)
248
+ rubocop (~> 1.21)
249
+ rubocop-shopify
250
+ sqlite3
251
+ stubberry
252
+
253
+ BUNDLED WITH
254
+ 2.5.11
@@ -1,11 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module NestedSelect
2
4
  module DeepMerger
3
-
4
5
  # {user_profile: [:zip_code]} + {user_profile: [:bio]} -> { user_profile: [:zip_code, :bio] }
5
6
  refine Hash do
6
7
  def deep_combine(other)
7
8
  merge!(other.except(*keys))
8
- merge!(other.slice(*keys).map{ |key, value| [key, [self[key], value].flatten.deep_combine_elements]}.to_h )
9
+ merge!(other.slice(*keys).map { |key, value| [key, [self[key], value].flatten.deep_combine_elements] }.to_h)
9
10
  end
10
11
  end
11
12
 
@@ -15,4 +16,4 @@ module NestedSelect
15
16
  end
16
17
  end
17
18
  end
18
- end
19
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module NestedSelect
2
4
  module Preloader
3
5
  module Association
@@ -11,13 +13,14 @@ module NestedSelect
11
13
  @nested_select_values = [*partial_select_values]
12
14
  ensure_nesting_selection_integrity!(association_nested_select_values)
13
15
  end
16
+
14
17
  def reflection_relation_keys_attributes
15
18
  foreign_key = reflection.foreign_key unless reflection.is_a?(ActiveRecord::Reflection::BelongsToReflection)
16
19
  [*foreign_key, *reflection.klass.primary_key].map(&:to_s)
17
20
  end
18
21
 
19
22
  def association_nested_select_values
20
- this_association_select_values = nested_select_values&.grep_v(Hash)&.map {_1.try(:to_s) }
23
+ this_association_select_values = nested_select_values&.grep_v(Hash)&.map { _1.try(:to_s) }
21
24
  return if this_association_select_values.blank?
22
25
 
23
26
  [*this_association_select_values, *reflection_relation_keys_attributes].uniq
@@ -38,7 +41,7 @@ module NestedSelect
38
41
  current_selection = nested_select_final_values.grep_v(Hash).map(&:to_s)
39
42
 
40
43
  basic_attributes_matched = (attributes_loaded & reflection.klass.column_names).tally ==
41
- (current_selection & reflection.klass.column_names).tally
44
+ (current_selection & reflection.klass.column_names).tally
42
45
 
43
46
  # this is not a 100% safe verification, but it will match cases with custom attributes selection for example:
44
47
  # "(SELECT COUNT(*) FROM images) as IMG_count" =~ /img_count/
@@ -58,4 +61,3 @@ module NestedSelect
58
61
  end
59
62
  end
60
63
  end
61
-
@@ -1,25 +1,29 @@
1
- # TODO describe Branch dedications
1
+ # frozen_string_literal: true
2
+
3
+ # TODO: describe Branch dedications
2
4
  module NestedSelect
3
5
  module Preloader
4
6
  module Branch
5
7
  attr_accessor :nested_select_values
8
+
6
9
  def preloaders_for_reflection(reflection, reflection_records)
7
10
  prevent_belongs_to_foreign_key_absence!(reflection)
8
11
 
9
12
  super.tap do |ldrs|
10
13
  # nested_select_values contains current level selection + nested relation selections
11
- ldrs.each{ _1.apply_nested_select_values(nested_select_values) } if nested_select_values.present?
14
+ ldrs.each { _1.apply_nested_select_values(nested_select_values) } if nested_select_values.present?
12
15
  end
13
16
  end
14
17
 
15
18
  private
19
+
16
20
  def prevent_belongs_to_foreign_key_absence!(reflection)
17
21
  return unless reflection.is_a?(ActiveRecord::Reflection::BelongsToReflection)
18
22
 
19
23
  # ActiveRecord will not raise in case its missing, so we should prevent silent error here
20
24
  if parent.nested_select_values.present? &&
21
- !parent.nested_select_values.grep_v(Hash)
22
- .map(&:to_sym).include?(reflection.foreign_key.to_sym)
25
+ !parent.nested_select_values.grep_v(Hash)
26
+ .map(&:to_sym).include?(reflection.foreign_key.to_sym)
23
27
 
24
28
  raise ActiveModel::MissingAttributeError, <<~ERR
25
29
  Parent reflection #{parent.association} was missing foreign key #{reflection.foreign_key} in nested selection,
@@ -30,4 +34,4 @@ module NestedSelect
30
34
  end
31
35
  end
32
36
  end
33
- end
37
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module NestedSelect
2
4
  module Preloader
3
5
  module ThroughAssociation
@@ -7,8 +9,8 @@ module NestedSelect
7
9
  associations: through_reflection.name,
8
10
  scope: through_scope,
9
11
  associate_by_default: false,
10
- ).tap do
11
- _1.apply_nested_select_values(nested_select_values.grep(Hash))
12
+ ).tap do
13
+ _1.apply_nested_select_values(nested_select_values&.grep(Hash))
12
14
  end.loaders
13
15
  end
14
16
 
@@ -16,8 +18,6 @@ module NestedSelect
16
18
  foreign_key = reflection.foreign_key unless reflection.parent_reflection.is_a?(ActiveRecord::Reflection::HasAndBelongsToManyReflection)
17
19
  [*foreign_key, *reflection.klass.primary_key].map(&:to_s)
18
20
  end
19
-
20
21
  end
21
22
  end
22
23
  end
23
-
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module NestedSelect
2
4
  module Preloader
3
5
  extend ActiveSupport::Autoload
@@ -13,13 +15,13 @@ module NestedSelect
13
15
  ActiveRecord::Associations::Preloader::Association.prepend(Association)
14
16
  end
15
17
 
16
- # first one will start from the roots [included_1: [{}], included_2: [{}] ]
18
+ # first one will start from the roots [{included_1: [{}], included_2: [{}]}]
17
19
  def apply_nested_select_values(nested_select_values)
18
20
  distribute_nested_select_over_loading_tree(@tree, nested_select_values)
19
21
  end
20
22
 
21
23
  def distribute_nested_select_over_loading_tree(sub_tree, nested_select_values)
22
- # nested_select_values = [:id, :title, comments: [:id, :body], cover: [:id, img: [:url]]]
24
+ # Ex: nested_select_values = [:id, :title, comments: [:id, :body], cover: [:id, img: [:url]]]
23
25
  return if nested_select_values.blank?
24
26
 
25
27
  sub_tree.nested_select_values = [*nested_select_values.grep_v(Hash)]
@@ -40,4 +42,4 @@ module NestedSelect
40
42
  end
41
43
  end
42
44
  end
43
- end
45
+ end
@@ -25,16 +25,34 @@ module NestedSelect
25
25
  # end
26
26
  # end
27
27
 
28
+ # this is copy of the original ActiveRecord::Relation#preload_associations method
29
+ # the only patching I' doing -- streaming down nested_select_values over the preloading trees
28
30
  def preload_associations(records) # :nodoc:
29
31
  preload = preload_values
30
32
  preload += includes_values unless eager_loading?
31
33
  scope = strict_loading_value ? StrictLoadingScope : nil
32
34
  preload.each do |associations|
33
35
  ActiveRecord::Associations::Preloader.new(records:, associations:, scope:)
34
- .tap{_1.apply_nested_select_values(nested_select_values) } # <-- Patching code
35
- .call
36
+ .tap do# <-- Patching code goes here
37
+ # at this moment nested_select_values will have a structure of an array of one hash element,
38
+ # with multiple keys matching those in associations, so we need to separate them per branch
39
+ if nested_select_values.present?
40
+ # associations will have a structure of either tree like hash or str/sym
41
+ # Ex: includes(:relation1, relation2: :nested_relation)
42
+ # associations will be either :relation1 or { relation2: :nested_relation }
43
+ root_association_name = (associations.try(:keys) || associations.try(:to_sym) || associations)
44
+ # nested_select_values, after deep_combine_elements
45
+ # will have structure of an array of single element at this moment:
46
+ # [{relation1: [columns..], relation2: [columns, nested_relation: [columns]] }]
47
+ # so we need to populate nested_select_values over associations branch
48
+ _1.apply_nested_select_values([nested_select_values.first.slice(*root_association_name)])
49
+ end
50
+ end.call
36
51
  end
37
52
  end
38
53
  end
39
54
 
40
55
  end
56
+
57
+
58
+ # ActiveRecord::Associations::Preloader.new(records:, associations:, scope:)