From 87a57a7f2b75a3559e8e07a0af7a11f89f440bfb Mon Sep 17 00:00:00 2001 From: Justin Berhang Date: Fri, 1 Mar 2024 19:21:34 +0000 Subject: [PATCH] patch bug fix for #1447 --- .../join_dependency.rb | 20 ++++++++++++++----- lib/ransack/version.rb | 2 +- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb b/lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb index f9cd1d8c..49f31db7 100644 --- a/lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb +++ b/lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb @@ -56,11 +56,21 @@ def construct_tables_for_association!(join_root, association) private def table_aliases_for(parent, node) + @joined_tables ||= {} node.reflection.chain.map { |reflection| - alias_tracker.aliased_table_for(reflection.klass.arel_table) do - root = reflection == node.reflection - name = reflection.alias_candidate(parent.table_name) - root ? name : "#{name}_join" + table, terminated = @joined_tables[reflection] + root = reflection == node.reflection + + if table && (!root || !terminated) + @joined_tables[reflection] = [table, true] if root + table + else + table = alias_tracker.aliased_table_for(reflection.klass.arel_table) do + name = reflection.alias_candidate(parent.table_name) + root ? name : "#{name}_join" + end + @joined_tables[reflection] ||= [table, root] if join_type == Arel::Nodes::OuterJoin + table end } end @@ -89,4 +99,4 @@ def walk_tree(associations, hash) end end -end +end \ No newline at end of file diff --git a/lib/ransack/version.rb b/lib/ransack/version.rb index d0c7682a..ce3b104f 100644 --- a/lib/ransack/version.rb +++ b/lib/ransack/version.rb @@ -1,3 +1,3 @@ module Ransack - VERSION = '4.0.0' + VERSION = '4.0.1' end