activerecord-filter 6.0.0.5 → 6.0.0.6
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.
- checksums.yaml +4 -4
- data/lib/active_record/filter.rb +46 -18
- data/lib/active_record/filter/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c34aa8bbd31df158c37ad5a80c46c31dff156bfb2a6e0bbb7e699d8919eb9aa1
|
4
|
+
data.tar.gz: eb154ad06ccc2b7b24c4b7ebea90bd4708b95a92db2b7d8fd92f74e2ca71c4c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d715a7a707abc56c16512e2aee2fe4fd4995e82466c3651d2caf14d38bb72f0201e0445c72614c4d295d05ccc6adf66666a1287644b33612d14aa472de804b9
|
7
|
+
data.tar.gz: 2f4535f34a7e762c4ce68abb18530e7f0b9ca9b7f8bd6a16e6389626f806806bc89a486104c17d61cb7361dc106437a203d0fe598ce8ace34136c23048282b66
|
data/lib/active_record/filter.rb
CHANGED
@@ -59,9 +59,22 @@ module ActiveRecord
|
|
59
59
|
end
|
60
60
|
elsif reflection = klass._reflections[key.to_s]
|
61
61
|
if value.is_a?(Hash)
|
62
|
-
relations <<
|
63
|
-
|
64
|
-
|
62
|
+
relations << if reflection.polymorphic?
|
63
|
+
join_klass = value[:as].safe_constantize
|
64
|
+
|
65
|
+
right_table = join_klass.arel_table.alias("#{join_klass.table_name}_as_#{reflection.name}")
|
66
|
+
left_table = reflection.active_record.arel_table
|
67
|
+
|
68
|
+
on = right_table[join_klass.primary_key].
|
69
|
+
eq(left_table[reflection.foreign_key]).
|
70
|
+
and(left_table[reflection.foreign_type].eq(join_klass.name))
|
71
|
+
|
72
|
+
left_table.join(right_table, Arel::Nodes::OuterJoin).on(on).join_sources
|
73
|
+
else
|
74
|
+
{
|
75
|
+
key => build_filter_joins(reflection.klass, value, [], custom)
|
76
|
+
}
|
77
|
+
end
|
65
78
|
elsif value.is_a?(Array)
|
66
79
|
value.each do |v|
|
67
80
|
relations << {
|
@@ -276,6 +289,7 @@ module ActiveRecord
|
|
276
289
|
raise "Not Supported: #{relation.name}"
|
277
290
|
end
|
278
291
|
end
|
292
|
+
|
279
293
|
when :belongs_to
|
280
294
|
if value == true || value == 'true'
|
281
295
|
return table.arel_attribute(relation.foreign_key).not_eq(nil)
|
@@ -284,26 +298,32 @@ module ActiveRecord
|
|
284
298
|
end
|
285
299
|
end
|
286
300
|
|
287
|
-
builder =
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
301
|
+
builder = if relation.polymorphic?
|
302
|
+
value = value.dup
|
303
|
+
klass = value.delete(:as).safe_constantize
|
304
|
+
|
305
|
+
self.class.new(TableMetadata.new(
|
306
|
+
klass,
|
307
|
+
Arel::Table.new("#{klass.table_name}_as_#{relation.name}", type_caster: klass.type_caster),
|
308
|
+
relation
|
309
|
+
))
|
310
|
+
else
|
311
|
+
self.class.new(TableMetadata.new(
|
312
|
+
relation.klass,
|
313
|
+
alias_tracker.aliased_table_for(
|
314
|
+
relation.table_name,
|
315
|
+
relation.alias_candidate(table.send(:arel_table).name),
|
316
|
+
relation.klass.type_caster
|
317
|
+
),
|
318
|
+
relation
|
319
|
+
))
|
320
|
+
end
|
296
321
|
builder.build_from_filter_hash(value, relation_trail + [relation.name], alias_tracker)
|
297
322
|
end
|
298
323
|
|
299
324
|
|
300
325
|
def expand_filter_for_join_table(relation, value, relation_trail, alias_tracker)
|
301
326
|
relation = relation.active_record._reflections[relation.active_record._reflections[relation.name.to_s].send(:delegate_reflection).options[:through].to_s]
|
302
|
-
STDOUT.puts [
|
303
|
-
relation.table_name,
|
304
|
-
relation.alias_candidate(table.send(:arel_table).name)
|
305
|
-
|
306
|
-
].inspect
|
307
327
|
builder = self.class.new(TableMetadata.new(
|
308
328
|
relation.klass,
|
309
329
|
alias_tracker.aliased_table_for(
|
@@ -380,7 +400,15 @@ class ActiveRecord::Relation
|
|
380
400
|
|
381
401
|
def filter!(filters)
|
382
402
|
js = ActiveRecord::PredicateBuilder.filter_joins(klass, filters)
|
383
|
-
js.each
|
403
|
+
js.flatten.each do |j|
|
404
|
+
if j.is_a?(String)
|
405
|
+
joins!(j)
|
406
|
+
elsif j.is_a?(Arel::Nodes::Join)
|
407
|
+
joins!(j)
|
408
|
+
elsif j.present?
|
409
|
+
left_outer_joins!(j)
|
410
|
+
end
|
411
|
+
end
|
384
412
|
@filters << filters
|
385
413
|
self
|
386
414
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-filter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.0.0.
|
4
|
+
version: 6.0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Bracy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -211,7 +211,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
211
211
|
- !ruby/object:Gem::Version
|
212
212
|
version: '0'
|
213
213
|
requirements: []
|
214
|
-
rubygems_version: 3.0.
|
214
|
+
rubygems_version: 3.0.6
|
215
215
|
signing_key:
|
216
216
|
specification_version: 4
|
217
217
|
summary: A safe way to accept user parameters and query against your ActiveRecord
|