ransack 2.4.2 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/cronjob.yml +6 -9
- data/.github/workflows/rubocop.yml +1 -1
- data/.github/workflows/test.yml +25 -34
- data/CHANGELOG.md +18 -1
- data/CONTRIBUTING.md +4 -3
- data/README.md +76 -10
- data/docs/release_process.md +2 -5
- data/lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb +20 -1
- data/lib/polyamorous/activerecord_6.0_ruby_2/join_dependency.rb +0 -1
- data/lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb +11 -1
- data/lib/polyamorous/activerecord_6.1_ruby_2/join_association.rb +0 -4
- data/lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb +0 -1
- data/lib/polyamorous/{activerecord_6.2_ruby_2 → activerecord_7.0_ruby_2}/join_association.rb +0 -0
- data/lib/polyamorous/{activerecord_6.2_ruby_2 → activerecord_7.0_ruby_2}/join_dependency.rb +0 -0
- data/lib/polyamorous/{activerecord_6.2_ruby_2 → activerecord_7.0_ruby_2}/reflection.rb +0 -0
- data/lib/polyamorous.rb +1 -0
- data/lib/ransack/adapters/active_record/base.rb +1 -1
- data/lib/ransack/adapters/active_record/context.rb +6 -2
- data/lib/ransack/adapters/active_record/ransack/nodes/condition.rb +10 -9
- data/lib/ransack/configuration.rb +16 -2
- data/lib/ransack/helpers/form_helper.rb +1 -1
- data/lib/ransack/locale/sv.yml +70 -0
- data/lib/ransack/nodes/sort.rb +2 -2
- data/lib/ransack/search.rb +2 -1
- data/lib/ransack/translate.rb +1 -1
- data/lib/ransack/version.rb +1 -1
- data/ransack.gemspec +2 -2
- data/spec/polyamorous/activerecord_compatibility_spec.rb +15 -0
- data/spec/polyamorous/join_association_spec.rb +1 -6
- data/spec/polyamorous/join_dependency_spec.rb +0 -16
- data/spec/ransack/adapters/active_record/base_spec.rb +18 -10
- data/spec/ransack/configuration_spec.rb +14 -0
- data/spec/ransack/helpers/form_helper_spec.rb +1 -2
- data/spec/ransack/nodes/condition_spec.rb +13 -0
- data/spec/ransack/search_spec.rb +117 -27
- data/spec/support/schema.rb +33 -0
- metadata +17 -16
- data/lib/polyamorous/activerecord_5.2_ruby_2/join_association.rb +0 -24
- data/lib/polyamorous/activerecord_5.2_ruby_2/join_dependency.rb +0 -79
- data/lib/polyamorous/activerecord_5.2_ruby_2/reflection.rb +0 -11
@@ -1,79 +0,0 @@
|
|
1
|
-
module Polyamorous
|
2
|
-
module JoinDependencyExtensions
|
3
|
-
# Replaces ActiveRecord::Associations::JoinDependency#build
|
4
|
-
def build(associations, base_klass)
|
5
|
-
associations.map do |name, right|
|
6
|
-
if name.is_a? Join
|
7
|
-
reflection = find_reflection base_klass, name.name
|
8
|
-
reflection.check_validity!
|
9
|
-
reflection.check_eager_loadable!
|
10
|
-
|
11
|
-
klass = if reflection.polymorphic?
|
12
|
-
name.klass || base_klass
|
13
|
-
else
|
14
|
-
reflection.klass
|
15
|
-
end
|
16
|
-
JoinAssociation.new(reflection, build(right, klass), name.klass, name.type)
|
17
|
-
else
|
18
|
-
reflection = find_reflection base_klass, name
|
19
|
-
reflection.check_validity!
|
20
|
-
reflection.check_eager_loadable!
|
21
|
-
|
22
|
-
if reflection.polymorphic?
|
23
|
-
raise ActiveRecord::EagerLoadPolymorphicError.new(reflection)
|
24
|
-
end
|
25
|
-
JoinAssociation.new(reflection, build(right, reflection.klass))
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def join_constraints(joins_to_add, join_type, alias_tracker)
|
31
|
-
@alias_tracker = alias_tracker
|
32
|
-
|
33
|
-
construct_tables!(join_root)
|
34
|
-
joins = make_join_constraints(join_root, join_type)
|
35
|
-
|
36
|
-
joins.concat joins_to_add.flat_map { |oj|
|
37
|
-
construct_tables!(oj.join_root)
|
38
|
-
if join_root.match?(oj.join_root) && join_root.table.name == oj.join_root.table.name
|
39
|
-
walk join_root, oj.join_root
|
40
|
-
else
|
41
|
-
make_join_constraints(oj.join_root, join_type)
|
42
|
-
end
|
43
|
-
}
|
44
|
-
end
|
45
|
-
|
46
|
-
private
|
47
|
-
def make_constraints(parent, child, join_type = Arel::Nodes::OuterJoin)
|
48
|
-
foreign_table = parent.table
|
49
|
-
foreign_klass = parent.base_klass
|
50
|
-
join_type = child.join_type || join_type if join_type == Arel::Nodes::InnerJoin
|
51
|
-
joins = child.join_constraints(foreign_table, foreign_klass, join_type, alias_tracker)
|
52
|
-
joins.concat child.children.flat_map { |c| make_constraints(child, c, join_type) }
|
53
|
-
end
|
54
|
-
|
55
|
-
module ClassMethods
|
56
|
-
# Prepended before ActiveRecord::Associations::JoinDependency#walk_tree
|
57
|
-
#
|
58
|
-
def walk_tree(associations, hash)
|
59
|
-
case associations
|
60
|
-
when TreeNode
|
61
|
-
associations.add_to_tree(hash)
|
62
|
-
when Hash
|
63
|
-
associations.each do |k, v|
|
64
|
-
cache =
|
65
|
-
if TreeNode === k
|
66
|
-
k.add_to_tree(hash)
|
67
|
-
else
|
68
|
-
hash[k] ||= {}
|
69
|
-
end
|
70
|
-
walk_tree(v, cache)
|
71
|
-
end
|
72
|
-
else
|
73
|
-
super(associations, hash)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
end
|
79
|
-
end
|