提交 158197b9 编写于 作者: A Aaron Patterson

eliminate duplicate code from to_sql

I don't really like passing the block, but this seems easiest for now
上级 d00f9692
......@@ -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
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册