Skip to content

Commit 0e25523

Browse files
Copilotscarroll32
andcommitted
Simplify fix: track all join types in @joined_tables to prevent duplicates
Co-authored-by: scarroll32 <[email protected]>
1 parent dab7eb8 commit 0e25523

File tree

2 files changed

+2
-20
lines changed

2 files changed

+2
-20
lines changed

lib/polyamorous/activerecord/join_dependency.rb

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,6 @@ def construct_tables_for_association!(join_root, association)
5353
tables
5454
end
5555

56-
def populate_joined_tables_from_existing_joins(join_nodes, relation)
57-
@joined_tables ||= {}
58-
59-
join_nodes.each do |join|
60-
next unless join.left.respond_to?(:name)
61-
62-
table_name = join.left.name
63-
64-
# Find reflections that correspond to this joined table
65-
relation.klass.reflect_on_all_associations.each do |reflection|
66-
if reflection.klass.table_name == table_name
67-
# Mark this reflection as already joined with the existing table
68-
@joined_tables[reflection] = [join.left, true]
69-
end
70-
end
71-
end
72-
end
73-
7456
private
7557

7658
def table_aliases_for(parent, node)
@@ -87,7 +69,7 @@ def table_aliases_for(parent, node)
8769
name = reflection.alias_candidate(parent.table_name)
8870
root ? name : "#{name}_join"
8971
end
90-
@joined_tables[reflection] ||= [table, root] if join_type == Arel::Nodes::OuterJoin
72+
@joined_tables[reflection] ||= [table, root]
9173
table
9274
end
9375
}

lib/ransack/adapters/active_record/context.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ def build_joins(relation)
310310
join_dependency.instance_variable_set(:@alias_tracker, alias_tracker)
311311

312312
# Track existing join nodes to prevent duplicate joins
313-
join_dependency.send(:populate_joined_tables_from_existing_joins, join_nodes, relation)
313+
join_dependency.populate_joined_tables_from_existing_joins(join_nodes, relation)
314314

315315
join_nodes.each do |join|
316316
join_dependency.send(:alias_tracker).aliases[join.left.name.downcase] = 1

0 commit comments

Comments
 (0)