refine-rails 2.12.2 → 2.13.1
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/app/models/refine/conditions/condition.rb +4 -1
- data/app/models/refine/conditions/has_through_id_relationship.rb +10 -0
- data/app/models/refine/conditions/uses_attributes.rb +36 -2
- data/app/models/refine/conditions/with_forced_index.rb +10 -0
- data/lib/refine/rails/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 745e07b54a0ea72e278c58749374e0a8a60283d0078b942c0a8c40dd3021f02b
|
4
|
+
data.tar.gz: 666166e9873ead413980823191557e80807e9cf8500216bf4c908665437a8e19
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57235d225ef0a85b5cb5a80895c0fa24279ef81f12d7838099b4251b2955dd7b7304f98219f8b2b43bd5f98e79b83c38c7aff4670d4e088353f28244fd148af7
|
7
|
+
data.tar.gz: 840b8fcbeb17129d367c23740e8498669bd8080f8e9861579e60377b53e7b9c4d7a93b273863d091025c1efed659a43ba3a46eeb88812ea1334464b150a6f22d
|
@@ -10,6 +10,8 @@ module Refine::Conditions
|
|
10
10
|
include HasMeta
|
11
11
|
include UsesAttributes
|
12
12
|
include HasRefinements
|
13
|
+
include HasThroughIdRelationship
|
14
|
+
include WithForcedIndex
|
13
15
|
include HasIcon
|
14
16
|
|
15
17
|
attr_reader :ensurances, :before_validations, :clause, :filter
|
@@ -122,7 +124,7 @@ module Refine::Conditions
|
|
122
124
|
# @param [Arel::Table] table The arel_table the query is built on
|
123
125
|
# @param [ActiveRecord::Relation] initial_query The base query the query is built on
|
124
126
|
# @return [Arel::Node]
|
125
|
-
def apply(input, table, initial_query, inverse_clause=false)
|
127
|
+
def apply(input, table, initial_query, inverse_clause=false, through_attribute=nil)
|
126
128
|
table ||= filter.table
|
127
129
|
# Ensurance validations are checking the developer configured correctly
|
128
130
|
run_ensurance_validations
|
@@ -150,6 +152,7 @@ module Refine::Conditions
|
|
150
152
|
return
|
151
153
|
end
|
152
154
|
# No longer a relationship attribute, apply condition normally
|
155
|
+
self.attribute = through_attribute if through_attribute
|
153
156
|
nodes = apply_condition(input, table, inverse_clause)
|
154
157
|
if !is_refinement && has_any_refinements?
|
155
158
|
refined_node = apply_refinements(input)
|
@@ -123,9 +123,43 @@ module Refine::Conditions
|
|
123
123
|
relation_table_being_queried = instance.klass.arel_table
|
124
124
|
|
125
125
|
relation_class = instance.klass
|
126
|
-
|
127
|
-
node_to_apply = apply(input, relation_table_being_queried, relation_class, inverse_clause)
|
128
126
|
|
127
|
+
if self.through_id_relationship
|
128
|
+
if instance.is_a? ActiveRecord::Reflection::ThroughReflection
|
129
|
+
through_reflection = instance.through_reflection
|
130
|
+
parent_foreign_key = through_reflection.foreign_key
|
131
|
+
child_foreign_key = instance.source_reflection.foreign_key
|
132
|
+
relation_table_being_queried = through_reflection.klass.arel_table
|
133
|
+
relation_class = through_reflection.klass
|
134
|
+
if(through_reflection.chain.count > 1)
|
135
|
+
# We need to shortcut the outer inner joins but allow the others to go as normal
|
136
|
+
parent_foreign_key = through_reflection.chain.last.foreign_key
|
137
|
+
parent_through_reflection = through_reflection.chain.last
|
138
|
+
join_sym = through_reflection.source_reflection_name
|
139
|
+
subquery_path = parent_through_reflection.klass.select(parent_foreign_key).joins(join_sym)
|
140
|
+
if(through_reflection.scope && through_reflection.scope.is_a?(Proc))
|
141
|
+
subquery_path = subquery_path.instance_exec(&through_reflection.scope)
|
142
|
+
end
|
143
|
+
subquery_path = subquery_path.arel
|
144
|
+
else
|
145
|
+
# Does not need any inner joins
|
146
|
+
subquery_path = through_reflection.klass.select(parent_foreign_key).arel
|
147
|
+
end
|
148
|
+
|
149
|
+
node_to_apply = apply(input, relation_table_being_queried, relation_class, inverse_clause, child_foreign_key)
|
150
|
+
else
|
151
|
+
raise Refine::Conditions::Errors::RelationshipError.new("with_through_id must be used with a has_many :through relationship")
|
152
|
+
end
|
153
|
+
else
|
154
|
+
node_to_apply = apply(input, relation_table_being_queried, relation_class, inverse_clause)
|
155
|
+
end
|
156
|
+
|
157
|
+
if self.forced_index
|
158
|
+
mysql_from_segment = "`#{through_reflection.table_name}` FORCE INDEX(`#{self.forced_index}`)"
|
159
|
+
# Ensuring input is sanitized
|
160
|
+
subquery_path = subquery_path.from(Arel.sql(mysql_from_segment))
|
161
|
+
end
|
162
|
+
|
129
163
|
complete_subquery = subquery_path.where(node_to_apply)
|
130
164
|
subquery = filter.get_pending_relationship_subquery || complete_subquery
|
131
165
|
filter.add_pending_relationship_subquery(subquery: subquery, primary_key: key_1(instance), secondary_key: nil, inverse_clause: inverse_clause)
|
data/lib/refine/rails/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: refine-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.13.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Colleen Schnettler
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2025-01-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -97,10 +97,12 @@ files:
|
|
97
97
|
- app/models/refine/conditions/has_icon.rb
|
98
98
|
- app/models/refine/conditions/has_meta.rb
|
99
99
|
- app/models/refine/conditions/has_refinements.rb
|
100
|
+
- app/models/refine/conditions/has_through_id_relationship.rb
|
100
101
|
- app/models/refine/conditions/numeric_condition.rb
|
101
102
|
- app/models/refine/conditions/option_condition.rb
|
102
103
|
- app/models/refine/conditions/text_condition.rb
|
103
104
|
- app/models/refine/conditions/uses_attributes.rb
|
105
|
+
- app/models/refine/conditions/with_forced_index.rb
|
104
106
|
- app/models/refine/filter.rb
|
105
107
|
- app/models/refine/filter/internationalized.rb
|
106
108
|
- app/models/refine/filters/blueprint_editor.rb
|