diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-12-14 11:25:47 -0800 |
---|---|---|
committer | Vijay Dev <vijaydev.cse@gmail.com> | 2010-12-16 01:49:29 +0530 |
commit | c02fd2acc575f3e90da12d4915390a80a48b7c8e (patch) | |
tree | 79db6782b1fe157e1cf5734a6d7b6d7e82020329 /activerecord/lib/active_record/associations/class_methods/join_dependency.rb | |
parent | 08ccca764498909faa2e4f9c69cee911e6395602 (diff) | |
download | rails-c02fd2acc575f3e90da12d4915390a80a48b7c8e.tar.gz rails-c02fd2acc575f3e90da12d4915390a80a48b7c8e.tar.bz2 rails-c02fd2acc575f3e90da12d4915390a80a48b7c8e.zip |
taking advantage of the JoinSource node in the SQL AST
Diffstat (limited to 'activerecord/lib/active_record/associations/class_methods/join_dependency.rb')
-rw-r--r-- | activerecord/lib/active_record/associations/class_methods/join_dependency.rb | 20 |
1 files changed, 6 insertions, 14 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 5a0ff942ca..a74d0a4ca8 100644 --- a/activerecord/lib/active_record/associations/class_methods/join_dependency.rb +++ b/activerecord/lib/active_record/associations/class_methods/join_dependency.rb @@ -47,24 +47,16 @@ module ActiveRecord end def count_aliases_from_table_joins(name) - return 0 if !@table_joins || Arel::Table === @table_joins + return 0 if Arel::Table === @table_joins # quoted_name should be downcased as some database adapters (Oracle) return quoted name in uppercase quoted_name = active_record.connection.quote_table_name(name).downcase - @table_joins.grep(Arel::Nodes::Join).map { |join| - right = join.right - case right - when Arel::Table - right.name.downcase == name ? 1 : 0 - when String - # Table names + table aliases - right.downcase.scan( - /join(?:\s+\w+)?\s+(\S+\s+)?#{quoted_name}\son/ - ).size - else - 0 - end + @table_joins.map { |join| + # Table names + table aliases + join.left.downcase.scan( + /join(?:\s+\w+)?\s+(\S+\s+)?#{quoted_name}\son/ + ).size }.sum end |