refine-rails 2.13.6 → 2.13.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 106e21d10bc77a60ebd5b8327c38ed45f1db7a47f3a0d7220b118478aa78048e
4
- data.tar.gz: 7f00f82bbfcb68a6249385d4e64298ed6d853451d7898cf23f994fa877b2c599
3
+ metadata.gz: ed9b99ff1ffc9ead0b84cead020b7abd3340b3b1ea85506ff51436469c8d38c8
4
+ data.tar.gz: e94ad2aec17f47227f2c590632266fda4d567fe757ed4eb7a139bd8e45d70c1a
5
5
  SHA512:
6
- metadata.gz: 602fbed9036cac55d1c8402624a690ab0b14acc0ce751346fd9f21f6aee42890d171b760a86c0e403c516508d3696febbeac07359cce8b794db6a66bbb202072
7
- data.tar.gz: 728e3a516839d718df569864d69fb888c0426a0f8854ebca194336dc5a06a40fbdf59343c0eb27ad056ca61ced186592df756aef0e468343d4ebc9c287929cb3
6
+ metadata.gz: 387b1428a0ac1d05da2291578c14b08b208499243c3f6c546afc437f62a932c343d675e1e0189337a752ed52cd3beef9e3f847f638ac238f08465e367629bad5
7
+ data.tar.gz: 436423c40e435a5c35290e5cc1572fc88f6ff4a57ba2e42b2370140811a52bcbf20ca8e1f4a046509292a3f9454de19b992baad4faf2792555535abc1c6c8d64
@@ -16,7 +16,7 @@ module Refine::Conditions
16
16
  include SupportsFlatQueries
17
17
 
18
18
  attr_reader :ensurances, :before_validations, :clause, :filter
19
- attr_accessor :display, :id, :is_refinement, :attribute
19
+ attr_accessor :display, :id, :is_refinement, :attribute, :is_flat_query
20
20
 
21
21
  I18N_PREFIX = "refine.refine_blueprints.condition."
22
22
 
@@ -18,6 +18,7 @@ module Refine::Conditions
18
18
  # This is mostly a copy of the `apply` method from the Condition module, but avoids recursion and the pending_subquery system
19
19
  def apply_flat(input, table, initial_query, inverse_clause=false)
20
20
  table ||= filter.table
21
+ @is_flat_query = true
21
22
  # Ensurance validations are checking the developer configured correctly
22
23
  run_ensurance_validations
23
24
  # Allow developer to modify user input
@@ -73,20 +74,27 @@ module Refine::Conditions
73
74
  end
74
75
 
75
76
  through_reflection = instance
77
+ forced_id = false
76
78
 
77
79
  # TODO - make sure we're accounting for refinements
78
80
  if @attribute == "id"
79
81
  # We're referencing a primary key ID, so we dont need the final join table and
80
82
  # can just reference the foreign key of the previous step in the relation chain
81
83
  through_reflection = get_through_reflection(instance: instance, relation: decompose_attribute[0])
84
+ unless condition_uses_different_database?(through_reflection.klass, query.model)
85
+ forced_id = true
86
+ @attribute = get_foreign_key_from_relation(instance: instance, reflection: through_reflection)
87
+ end
88
+ end
89
+
90
+ unless condition_uses_different_database?(through_reflection.klass, query.model)
82
91
  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
85
- @attribute = get_foreign_key_from_relation(instance: instance, reflection: through_reflection)
86
- # else
87
- # puts "TODO - not referencing an ID in attribute"
88
92
  end
93
+ # TODO - this is not the right long-term place for this.
94
+ apply_flat_relational_condition(instance: instance, relation: relation, through_reflection: through_reflection, input: input, table: table, query: query, inverse_clause: inverse_clause, forced_id: forced_id)
95
+ end
89
96
 
97
+ def apply_flat_relational_condition(instance:, relation:, through_reflection:, input:, table:, query:, inverse_clause:, forced_id: false)
90
98
  unless instance
91
99
  raise "Relationship does not exist for #{relation}."
92
100
  end
@@ -94,13 +102,18 @@ module Refine::Conditions
94
102
  relation_table_being_queried = through_reflection.klass.arel_table
95
103
  relation_class = through_reflection.klass
96
104
 
97
- instance = get_reflection_object(query, relation)
105
+ instance = get_reflection_object(query, relation) if forced_id
106
+
98
107
  key_1 = key_1(instance)
99
108
  key_2 = key_2(instance)
100
- if condiiton_uses_different_database?(relation_class, query.model)
109
+ if condition_uses_different_database?(relation_class, query.model)
101
110
  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
111
  else
103
- nodes = apply(input, relation_table_being_queried, query, inverse_clause, key_2)
112
+ if forced_id
113
+ nodes = apply(input, relation_table_being_queried, query, inverse_clause, key_2)
114
+ else
115
+ nodes = apply(input, relation_table_being_queried, query, inverse_clause)
116
+ end
104
117
  end
105
118
 
106
119
  if !is_refinement && has_any_refinements?
@@ -109,7 +122,6 @@ module Refine::Conditions
109
122
  nodes = nodes.and(refined_node) if refined_node
110
123
  end
111
124
  nodes
112
-
113
125
  end
114
126
 
115
127
  # When we need to go to another DB for the relation. We need to do a separate query to get the IDS of
@@ -148,6 +160,7 @@ module Refine::Conditions
148
160
  # If we already are tracking the relation with a left joins, don't overwrite it
149
161
  # puts "adding a pending join for relation: #{relation} with join type: #{join_type}"
150
162
  unless join_type == :inner && filter.pending_joins[relation] == :left
163
+ filter.needs_distinct = true
151
164
  filter.pending_joins[relation] = join_type
152
165
  end
153
166
  end
@@ -161,7 +174,7 @@ module Refine::Conditions
161
174
  end
162
175
  end
163
176
 
164
- def condiiton_uses_different_database?(current_model, parent_model)
177
+ def condition_uses_different_database?(current_model, parent_model)
165
178
  # Are the queries on different databases?
166
179
  parent_model.connection_db_config.configuration_hash != current_model.connection_db_config.configuration_hash
167
180
  end
@@ -1,5 +1,5 @@
1
1
  module Refine
2
2
  module Rails
3
- VERSION = "2.13.6"
3
+ VERSION = "2.13.7"
4
4
  end
5
5
  end
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.6
4
+ version: 2.13.7
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-20 00:00:00.000000000 Z
12
+ date: 2025-03-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails