refine-rails 2.13.4 → 2.13.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/app/models/refine/conditions/supports_flat_queries.rb +36 -10
- data/app/models/refine/conditions/uses_attributes.rb +11 -7
- data/app/models/refine/flat_query_tools.rb +8 -1
- data/app/models/refine/inspector.rb +7 -0
- data/app/models/refine/tracks_pending_relationship_subqueries.rb +1 -0
- data/app/views/refine/advanced_inline/criteria/new.turbo_stream.erb +0 -1
- data/lib/refine/rails/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 106e21d10bc77a60ebd5b8327c38ed45f1db7a47f3a0d7220b118478aa78048e
|
4
|
+
data.tar.gz: 7f00f82bbfcb68a6249385d4e64298ed6d853451d7898cf23f994fa877b2c599
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 602fbed9036cac55d1c8402624a690ab0b14acc0ce751346fd9f21f6aee42890d171b760a86c0e403c516508d3696febbeac07359cce8b794db6a66bbb202072
|
7
|
+
data.tar.gz: 728e3a516839d718df569864d69fb888c0426a0f8854ebca194336dc5a06a40fbdf59343c0eb27ad056ca61ced186592df756aef0e468343d4ebc9c287929cb3
|
@@ -15,6 +15,7 @@ module Refine::Conditions
|
|
15
15
|
# @param [ActiveRecord::Relation] initial_query The base query the query is built on
|
16
16
|
# @param [Bool] inverse_clause Whether to invert the clause
|
17
17
|
# @return [Arel::Node]
|
18
|
+
# This is mostly a copy of the `apply` method from the Condition module, but avoids recursion and the pending_subquery system
|
18
19
|
def apply_flat(input, table, initial_query, inverse_clause=false)
|
19
20
|
table ||= filter.table
|
20
21
|
# Ensurance validations are checking the developer configured correctly
|
@@ -27,6 +28,7 @@ module Refine::Conditions
|
|
27
28
|
# TODO Determine right place to set the clause
|
28
29
|
validate_user_input(input)
|
29
30
|
if input.dig(:filter_refinement).present?
|
31
|
+
# TODO - Handle refinements. Currently not working for flat queries because its dependent on the pending_subquery system
|
30
32
|
|
31
33
|
filter_condition = call_proc_if_callable(@filter_refinement_proc)
|
32
34
|
# Set the filter on the filter_condition to be the current_condition's filter
|
@@ -39,7 +41,7 @@ module Refine::Conditions
|
|
39
41
|
end
|
40
42
|
|
41
43
|
if is_relationship_attribute?
|
42
|
-
return handle_flat_relational_condition(input: input, query: initial_query, inverse_clause: inverse_clause)
|
44
|
+
return handle_flat_relational_condition(input: input, table: table, query: initial_query, inverse_clause: inverse_clause)
|
43
45
|
end
|
44
46
|
# Not a relationship attribute, apply condition normally
|
45
47
|
nodes = apply_condition(input, table, inverse_clause)
|
@@ -51,7 +53,7 @@ module Refine::Conditions
|
|
51
53
|
nodes
|
52
54
|
end
|
53
55
|
|
54
|
-
def handle_flat_relational_condition(input:, query:, inverse_clause:)
|
56
|
+
def handle_flat_relational_condition(input:, table:, query:, inverse_clause:)
|
55
57
|
# Split on first .
|
56
58
|
decompose_attribute = @attribute.split(".", 2)
|
57
59
|
# Attribute now is the back half of the initial attribute
|
@@ -78,9 +80,11 @@ module Refine::Conditions
|
|
78
80
|
# can just reference the foreign key of the previous step in the relation chain
|
79
81
|
through_reflection = get_through_reflection(instance: instance, relation: decompose_attribute[0])
|
80
82
|
add_pending_joins_if_needed(instance: instance, reflection: through_reflection, input: input)
|
83
|
+
# TODO - this is not the right long-term place for this.
|
84
|
+
filter.needs_distinct = true
|
81
85
|
@attribute = get_foreign_key_from_relation(instance: instance, reflection: through_reflection)
|
82
|
-
else
|
83
|
-
|
86
|
+
# else
|
87
|
+
# puts "TODO - not referencing an ID in attribute"
|
84
88
|
end
|
85
89
|
|
86
90
|
unless instance
|
@@ -90,7 +94,15 @@ module Refine::Conditions
|
|
90
94
|
relation_table_being_queried = through_reflection.klass.arel_table
|
91
95
|
relation_class = through_reflection.klass
|
92
96
|
|
93
|
-
|
97
|
+
instance = get_reflection_object(query, relation)
|
98
|
+
key_1 = key_1(instance)
|
99
|
+
key_2 = key_2(instance)
|
100
|
+
if condiiton_uses_different_database?(relation_class, query.model)
|
101
|
+
nodes = handle_flat_cross_database_condition(input: input, table: table, relation_class: relation_class, relation_table_being_queried: relation_table_being_queried, inverse_clause: inverse_clause, key_1: key_1, key_2: key_2)
|
102
|
+
else
|
103
|
+
nodes = apply(input, relation_table_being_queried, query, inverse_clause, key_2)
|
104
|
+
end
|
105
|
+
|
94
106
|
if !is_refinement && has_any_refinements?
|
95
107
|
refined_node = apply_refinements(input)
|
96
108
|
# Count refinement will return nil because it directly modified pending relationship subquery
|
@@ -98,11 +110,20 @@ module Refine::Conditions
|
|
98
110
|
end
|
99
111
|
nodes
|
100
112
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
113
|
+
end
|
114
|
+
|
115
|
+
# When we need to go to another DB for the relation. We need to do a separate query to get the IDS of
|
116
|
+
# the records matching the condition that will then be passed into the primary query.
|
117
|
+
def handle_flat_cross_database_condition(input:, table:, relation_class:, relation_table_being_queried:, inverse_clause:, key_1:, key_2:)
|
118
|
+
relational_query = relation_class.select(key_2).arel
|
119
|
+
node = apply(input, relation_table_being_queried, relation_class, inverse_clause)
|
120
|
+
relational_query = relational_query.where(node)
|
121
|
+
array_of_ids = relation_class.connection.exec_query(relational_query.to_sql).rows.flatten
|
122
|
+
if array_of_ids.length == 1
|
123
|
+
nodes = table[:"#{key_1}"].eq(array_of_ids.first)
|
124
|
+
else
|
125
|
+
nodes = table[:"#{key_1}"].in(array_of_ids)
|
126
|
+
end
|
106
127
|
end
|
107
128
|
|
108
129
|
def get_through_reflection(instance:, relation:)
|
@@ -139,5 +160,10 @@ module Refine::Conditions
|
|
139
160
|
add_pending_join(reflection.name, :inner)
|
140
161
|
end
|
141
162
|
end
|
163
|
+
|
164
|
+
def condiiton_uses_different_database?(current_model, parent_model)
|
165
|
+
# Are the queries on different databases?
|
166
|
+
parent_model.connection_db_config.configuration_hash != current_model.connection_db_config.configuration_hash
|
167
|
+
end
|
142
168
|
end
|
143
169
|
end
|
@@ -21,13 +21,7 @@ module Refine::Conditions
|
|
21
21
|
|
22
22
|
# Get the Reflection object which defines the relationship between query and relation
|
23
23
|
# First iteration pull relationship using base query which responds to model.
|
24
|
-
instance =
|
25
|
-
query.model.reflect_on_association(relation.to_sym)
|
26
|
-
else
|
27
|
-
# When query is sent in as subquery (recursive) the query object is the model class pulled from the
|
28
|
-
# previous instance value
|
29
|
-
query.reflect_on_association(relation.to_sym)
|
30
|
-
end
|
24
|
+
instance = get_reflection_object(query, relation)
|
31
25
|
|
32
26
|
unless instance
|
33
27
|
raise "Relationship does not exist for #{relation}."
|
@@ -69,6 +63,16 @@ module Refine::Conditions
|
|
69
63
|
end
|
70
64
|
end
|
71
65
|
|
66
|
+
def get_reflection_object(query, relation)
|
67
|
+
if query.respond_to? :model
|
68
|
+
query.model.reflect_on_association(relation.to_sym)
|
69
|
+
else
|
70
|
+
# When query is sent in as subquery (recursive) the query object is the model class pulled from the
|
71
|
+
# previous instance value
|
72
|
+
query.reflect_on_association(relation.to_sym)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
72
76
|
def create_pending_wherein_subquery(input:, relation:, instance:, query:)
|
73
77
|
# This method builds out the linking keys between the provided query model and the relation
|
74
78
|
# and saves it to pending relationship subqueries
|
@@ -3,7 +3,7 @@
|
|
3
3
|
# NOTE: This is more specialized query construction and it is up to the implementer to use the inspector tools to ensure this is only being used for supported queries
|
4
4
|
module Refine
|
5
5
|
module FlatQueryTools
|
6
|
-
attr_accessor :pending_joins, :applied_conditions
|
6
|
+
attr_accessor :pending_joins, :applied_conditions, :needs_distinct
|
7
7
|
|
8
8
|
def pending_joins
|
9
9
|
@pending_joins ||= {}
|
@@ -13,6 +13,10 @@ module Refine
|
|
13
13
|
@applied_conditions ||= {}
|
14
14
|
end
|
15
15
|
|
16
|
+
def needs_distinct?
|
17
|
+
@needs_distinct ||= false
|
18
|
+
end
|
19
|
+
|
16
20
|
def get_flat_query
|
17
21
|
raise "Initial query must exist" if initial_query.nil?
|
18
22
|
raise "Cannot make flat query for a filter using OR conditions" if uses_or?
|
@@ -51,6 +55,9 @@ module Refine
|
|
51
55
|
if pending_joins.present?
|
52
56
|
apply_pending_joins
|
53
57
|
end
|
58
|
+
if needs_distinct?
|
59
|
+
@relation = @relation.distinct
|
60
|
+
end
|
54
61
|
@relation
|
55
62
|
end
|
56
63
|
|
@@ -37,5 +37,12 @@ module Refine
|
|
37
37
|
@blueprint.select{|c| c[:type] == "criterion" && negative_clauses.include?(c[:input][:clause])}.any?
|
38
38
|
end
|
39
39
|
|
40
|
+
def has_duplicate_conditions?
|
41
|
+
return false if @blueprint.nil? || @blueprint.empty?
|
42
|
+
conditions = @blueprint.select{|c| c[:type] == "criterion"}
|
43
|
+
condition_ids = conditions.map{|c| c[:condition_id]}
|
44
|
+
condition_ids.length != condition_ids.uniq.length
|
45
|
+
end
|
46
|
+
|
40
47
|
end
|
41
48
|
end
|
@@ -116,6 +116,7 @@ module Refine
|
|
116
116
|
subset.each do |relation, subquery|
|
117
117
|
# relation = table
|
118
118
|
# subquery.keys = [:instance, :query, :key, :secondary] possibly (:children)
|
119
|
+
|
119
120
|
if subquery.dig(:children).present?
|
120
121
|
# Send in the values at children as the subset hash and remove from existing subquery
|
121
122
|
child_nodes = subquery.delete(:children)
|
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.13.
|
4
|
+
version: 2.13.6
|
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: 2025-02-
|
12
|
+
date: 2025-02-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|