diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-10-13 16:56:30 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-10-13 16:56:30 -0700 |
commit | 158197b91d34b5ef2a4c06fb12a440d0b88d693d (patch) | |
tree | 7675b6bd640da4bab3ca1cf4cad7971e1738a133 /activerecord | |
parent | d00f9692b82deb8f90c4b3fb56f9e22cceb0e470 (diff) | |
download | rails-158197b91d34b5ef2a4c06fb12a440d0b88d693d.tar.gz rails-158197b91d34b5ef2a4c06fb12a440d0b88d693d.tar.bz2 rails-158197b91d34b5ef2a4c06fb12a440d0b88d693d.zip |
eliminate duplicate code from to_sql
I don't really like passing the block, but this seems easiest for now
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/relation.rb | 4 | ||||
-rw-r--r-- | activerecord/lib/active_record/relation/finder_methods.rb | 12 |
2 files changed, 9 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index 8d11fa4e57..c49f9a9f3d 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -507,9 +507,7 @@ module ActiveRecord 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 diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb index 3d687b927d..b2d770ba93 100644 --- a/activerecord/lib/active_record/relation/finder_methods.rb +++ b/activerecord/lib/active_record/relation/finder_methods.rb @@ -244,11 +244,15 @@ module ActiveRecord 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 |