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/lib/active_record/relation | |
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/lib/active_record/relation')
-rw-r--r-- | activerecord/lib/active_record/relation/finder_methods.rb | 12 |
1 files changed, 8 insertions, 4 deletions
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 |