diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-08-29 15:01:17 +0100 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2011-08-29 15:05:47 +0100 |
commit | 735d985b0162976e7e900cf36d4cbb0d657fb5e9 (patch) | |
tree | 6d28ea963504b2f458b81eb6c32ac471b937f316 /activerecord/lib/active_record/associations/alias_tracker.rb | |
parent | fd22d040fef48778a519825dd2f0cf2fd73a8965 (diff) | |
download | rails-735d985b0162976e7e900cf36d4cbb0d657fb5e9.tar.gz rails-735d985b0162976e7e900cf36d4cbb0d657fb5e9.tar.bz2 rails-735d985b0162976e7e900cf36d4cbb0d657fb5e9.zip |
The join_nodes must be passed to the JoinDependency initializer and therefore counted by the alias tracker. This is because the association_joins are aliased on initialization and then the tables are cached, so it is no use to alias the join_nodes later. Fixes #2556.
Diffstat (limited to 'activerecord/lib/active_record/associations/alias_tracker.rb')
-rw-r--r-- | activerecord/lib/active_record/associations/alias_tracker.rb | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/associations/alias_tracker.rb b/activerecord/lib/active_record/associations/alias_tracker.rb index 92ed844a2e..0248c7483c 100644 --- a/activerecord/lib/active_record/associations/alias_tracker.rb +++ b/activerecord/lib/active_record/associations/alias_tracker.rb @@ -53,12 +53,18 @@ module ActiveRecord # quoted_name should be downcased as some database adapters (Oracle) return quoted name in uppercase quoted_name = connection.quote_table_name(name).downcase - table_joins.map { |join| - # Table names + table aliases - join.left.downcase.scan( - /join(?:\s+\w+)?\s+(\S+\s+)?#{quoted_name}\son/ - ).size - }.sum + counts = table_joins.map do |join| + if join.is_a?(Arel::Nodes::StringJoin) + # Table names + table aliases + join.left.downcase.scan( + /join(?:\s+\w+)?\s+(\S+\s+)?#{quoted_name}\son/ + ).size + else + join.left.table_name == name ? 1 : 0 + end + end + + counts.sum end def truncate(name) |