Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

eliminate duplicate code from to_sql

I don't really like passing the block, but this seems easiest for now
  • Loading branch information...
commit 158197b91d34b5ef2a4c06fb12a440d0b88d693d 1 parent d00f969
@tenderlove tenderlove authored
View
4 activerecord/lib/active_record/relation.rb
@@ -507,9 +507,7 @@ def to_sql
visitor = connection.visitor
if eager_loading?
- join_dependency = construct_join_dependency
- relation = except :select
- relation = construct_relation_for_association_find(join_dependency, relation)
+ find_with_associations { |rel| relation = rel }
end
ast = relation.arel.ast
View
12 activerecord/lib/active_record/relation/finder_methods.rb
@@ -244,11 +244,15 @@ def find_with_associations
join_dependency = construct_join_dependency
relation = except :select
relation = construct_relation_for_association_find(join_dependency, relation)
- if ActiveRecord::NullRelation === relation
- []
+ if block_given?
+ yield relation
else
- rows = connection.select_all(relation.arel, 'SQL', relation.bind_values.dup)
- join_dependency.instantiate(rows)
+ if ActiveRecord::NullRelation === relation
+ []
+ else
+ rows = connection.select_all(relation.arel, 'SQL', relation.bind_values.dup)
+ join_dependency.instantiate(rows)
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.