aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-12-07 17:05:15 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2010-12-07 17:05:15 -0800
commitd98cb5153dad97cde82ec91a1993043cfa9bc0e4 (patch)
tree7f11d288aceebb754c11c44156d94f0186d6ecb2
parent2d9d6cd4c263f639adf8e26c7d95e7772e0c4eb7 (diff)
downloadrails-d98cb5153dad97cde82ec91a1993043cfa9bc0e4.tar.gz
rails-d98cb5153dad97cde82ec91a1993043cfa9bc0e4.tar.bz2
rails-d98cb5153dad97cde82ec91a1993043cfa9bc0e4.zip
JoinDependency is always created with an AST now
-rw-r--r--activerecord/lib/active_record/associations/class_methods/join_dependency.rb14
-rw-r--r--activerecord/lib/active_record/relation/query_methods.rb16
2 files changed, 25 insertions, 5 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
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb
index 2933d427f0..194ce881e0 100644
--- a/activerecord/lib/active_record/relation/query_methods.rb
+++ b/activerecord/lib/active_record/relation/query_methods.rb
@@ -185,6 +185,20 @@ module ActiveRecord
arel.join_sql
end
+ def custom_join_ast(joins)
+ joins = joins.reject { |join| join.blank? }
+
+ return if joins.empty?
+
+ @implicit_readonly = true
+
+ head = table.create_string_join(table, joins.shift)
+
+ joins.inject(head) do |ast, join|
+ ast.right = table.create_string_join(ast.right, join)
+ end
+ end
+
def build_arel
arel = table
@@ -256,7 +270,7 @@ module ActiveRecord
non_association_joins = (joins - association_joins - stashed_association_joins)
custom_joins = custom_join_sql(non_association_joins)
- join_dependency = ActiveRecord::Associations::ClassMethods::JoinDependency.new(@klass, association_joins, custom_joins)
+ join_dependency = ActiveRecord::Associations::ClassMethods::JoinDependency.new(@klass, association_joins, custom_join_ast(non_association_joins))
join_dependency.graft(*stashed_association_joins)