diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-12-07 16:48:59 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-12-07 16:48:59 -0800 |
commit | 2d9d6cd4c263f639adf8e26c7d95e7772e0c4eb7 (patch) | |
tree | 77f3d650bc01bbd0983a1bf7b0231ad70dd629ee /activerecord/lib/active_record/associations/class_methods/join_dependency.rb | |
parent | d6133209ce54bac430e63ec512251eae182b79e1 (diff) | |
download | rails-2d9d6cd4c263f639adf8e26c7d95e7772e0c4eb7.tar.gz rails-2d9d6cd4c263f639adf8e26c7d95e7772e0c4eb7.tar.bz2 rails-2d9d6cd4c263f639adf8e26c7d95e7772e0c4eb7.zip |
passing the ast to JoinDependency
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 | 13 |
1 files changed, 11 insertions, 2 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 34928bc764..86d43f21d3 100644 --- a/activerecord/lib/active_record/associations/class_methods/join_dependency.rb +++ b/activerecord/lib/active_record/associations/class_methods/join_dependency.rb @@ -45,11 +45,20 @@ module ActiveRecord end def count_aliases_from_table_joins(name) - return 0 unless @table_joins + return 0 if !@table_joins || Arel::Table === @table_joins + 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) + }.sum + end + + def count_aliases_from_string(join_sql, name) # 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).downcase - join_sql = @table_joins.downcase # Table names join_sql.scan(/join(?:\s+\w+)?\s+#{quoted_name}\son/).size + # Table aliases |