ransack 3.0.0 → 3.2.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/deploy.yml +35 -0
- data/.github/workflows/test-deploy.yml +29 -0
- data/.github/workflows/test.yml +10 -25
- data/CHANGELOG.md +47 -0
- data/CONTRIBUTING.md +1 -1
- data/Gemfile +2 -2
- data/README.md +1 -1
- data/docs/.gitignore +0 -1
- data/docs/docs/getting-started/using-predicates.md +1 -1
- data/docs/docs/going-further/acts-as-taggable-on.md +114 -0
- data/docs/docs/going-further/documentation.md +14 -2
- data/docs/docs/going-further/merging-searches.md +1 -1
- data/docs/docs/going-further/polymorphic-search.md +40 -0
- data/docs/docs/going-further/wiki-contributors.md +82 -0
- data/docs/docusaurus.config.js +2 -3
- data/docs/yarn.lock +3 -3
- data/lib/polyamorous/activerecord_6.1_ruby_2/reflection.rb +11 -1
- data/lib/polyamorous/activerecord_7.1_ruby_2/join_association.rb +1 -0
- data/lib/polyamorous/activerecord_7.1_ruby_2/join_dependency.rb +1 -0
- data/lib/polyamorous/activerecord_7.1_ruby_2/reflection.rb +1 -0
- data/lib/ransack/adapters/active_record/context.rb +17 -49
- data/lib/ransack/adapters/active_record/ransack/nodes/condition.rb +2 -10
- data/lib/ransack/constants.rb +0 -3
- data/lib/ransack/helpers/form_helper.rb +1 -1
- data/lib/ransack/version.rb +1 -1
- data/ransack.gemspec +3 -3
- data/spec/helpers/polyamorous_helper.rb +2 -8
- data/spec/ransack/helpers/form_helper_spec.rb +24 -0
- metadata +16 -12
- data/docs/package-lock.json +0 -9207
- data/lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb +0 -20
- data/lib/polyamorous/activerecord_6.0_ruby_2/join_dependency.rb +0 -79
- data/lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb +0 -11
@@ -1,20 +0,0 @@
|
|
1
|
-
module Polyamorous
|
2
|
-
module JoinAssociationExtensions
|
3
|
-
include SwappingReflectionClass
|
4
|
-
def self.prepended(base)
|
5
|
-
base.class_eval { attr_reader :join_type }
|
6
|
-
end
|
7
|
-
|
8
|
-
def initialize(reflection, children, polymorphic_class = nil, join_type = Arel::Nodes::InnerJoin)
|
9
|
-
@join_type = join_type
|
10
|
-
if polymorphic_class && ::ActiveRecord::Base > polymorphic_class
|
11
|
-
swapping_reflection_klass(reflection, polymorphic_class) do |reflection|
|
12
|
-
super(reflection, children)
|
13
|
-
self.reflection.options[:polymorphic] = true
|
14
|
-
end
|
15
|
-
else
|
16
|
-
super(reflection, children)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -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, 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, oj.join_type
|
40
|
-
else
|
41
|
-
make_join_constraints(oj.join_root, oj.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
|