aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/class_methods
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/associations/class_methods')
-rw-r--r--activerecord/lib/active_record/associations/class_methods/join_dependency.rb14
1 files changed, 10 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/associations/class_methods/join_dependency.rb b/activerecord/lib/active_record/associations/class_methods/join_dependency.rb
index 86d43f21d3..928e8152a5 100644
--- a/activerecord/lib/active_record/associations/class_methods/join_dependency.rb
+++ b/activerecord/lib/active_record/associations/class_methods/join_dependency.rb
@@ -49,10 +49,16 @@ module ActiveRecord
return count_aliases_from_string(@table_joins.downcase, name) if String === @table_joins
- @table_joins.grep(Arel::Table).find_all { |table|
- table.name.downcase == name
- }.length + @table_joins.grep(String).map { |s|
- count_aliases_from_string(s, name)
+ @table_joins.grep(Arel::Nodes::Join).map { |join|
+ right = join.right
+ case right
+ when Arel::Table
+ right.name.downcase == name ? 1 : 0
+ when String
+ count_aliases_from_string(right.downcase, name)
+ else
+ 0
+ end
}.sum
end