aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-12-14 11:25:47 -0800
committerVijay Dev <vijaydev.cse@gmail.com>2010-12-16 01:49:29 +0530
commitc02fd2acc575f3e90da12d4915390a80a48b7c8e (patch)
tree79db6782b1fe157e1cf5734a6d7b6d7e82020329 /activerecord/lib/active_record/relation
parent08ccca764498909faa2e4f9c69cee911e6395602 (diff)
downloadrails-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/relation')
-rw-r--r--activerecord/lib/active_record/relation/finder_methods.rb2
-rw-r--r--activerecord/lib/active_record/relation/query_methods.rb23
2 files changed, 8 insertions, 17 deletions
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb
index 906ad7699c..8bc28c06cb 100644
--- a/activerecord/lib/active_record/relation/finder_methods.rb
+++ b/activerecord/lib/active_record/relation/finder_methods.rb
@@ -187,7 +187,7 @@ module ActiveRecord
def find_with_associations
including = (@eager_load_values + @includes_values).uniq
- join_dependency = ActiveRecord::Associations::ClassMethods::JoinDependency.new(@klass, including, nil)
+ join_dependency = ActiveRecord::Associations::ClassMethods::JoinDependency.new(@klass, including, [])
rows = construct_relation_for_association_find(join_dependency).to_a
join_dependency.instantiate(rows)
rescue ThrowResult
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb
index 51a39be065..67a94cec85 100644
--- a/activerecord/lib/active_record/relation/query_methods.rb
+++ b/activerecord/lib/active_record/relation/query_methods.rb
@@ -191,27 +191,19 @@ module ActiveRecord
def custom_join_ast(table, joins)
joins = joins.reject { |join| join.blank? }
- return if joins.empty?
+ return [] if joins.empty?
@implicit_readonly = true
- joins.map! do |join|
+ joins.map do |join|
case join
when Array
join = Arel.sql(join.join(' ')) if array_of_strings?(join)
when String
join = Arel.sql(join)
end
- join
+ table.create_string_join(join)
end
-
- head = table.create_string_join(table, joins.shift)
-
- joins.inject(head) do |ast, join|
- ast.right = table.create_string_join(ast.right, join)
- end
-
- head
end
def collapse_wheres(arel, wheres)
@@ -256,9 +248,9 @@ module ActiveRecord
stashed_association_joins = joins.grep(ActiveRecord::Associations::ClassMethods::JoinDependency::JoinAssociation)
non_association_joins = (joins - association_joins - stashed_association_joins)
- join_ast = custom_join_ast(manager.froms.first, non_association_joins)
+ join_list = custom_join_ast(manager, non_association_joins)
- join_dependency = ActiveRecord::Associations::ClassMethods::JoinDependency.new(@klass, association_joins, join_ast)
+ join_dependency = ActiveRecord::Associations::ClassMethods::JoinDependency.new(@klass, association_joins, join_list)
join_dependency.graft(*stashed_association_joins)
@@ -269,10 +261,9 @@ module ActiveRecord
association.join_to(manager)
end
- return manager unless join_ast
+ return manager unless join_list
- join_ast.left = manager.froms.first
- manager.from join_ast
+ join_list.each { |j| manager.from j }
manager
end