diff options
author | knapo <knapo@knapo.net> | 2011-07-07 11:40:11 +0200 |
---|---|---|
committer | knapo <knapo@knapo.net> | 2011-07-07 11:40:11 +0200 |
commit | 2ca9b6dfab81c17bdad7d367c97e39c9ac25c075 (patch) | |
tree | 36262f16c0245c510f9f9fdf14bd2bfcfa6bcba7 /activerecord | |
parent | 1bad08f1168709a657110281f9a9e17c514eda92 (diff) | |
download | rails-2ca9b6dfab81c17bdad7d367c97e39c9ac25c075.tar.gz rails-2ca9b6dfab81c17bdad7d367c97e39c9ac25c075.tar.bz2 rails-2ca9b6dfab81c17bdad7d367c97e39c9ac25c075.zip |
Make `ActiveRecord::Batches#find_each` to not return `self`.
This caused that `find_each` was producing extra db call taking all the records from db, and was less efficient than `ActiveRecord::Base#all`.
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/relation/batches.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/batches_test.rb | 7 |
2 files changed, 7 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/relation/batches.rb b/activerecord/lib/active_record/relation/batches.rb index d52b84179f..46ab67d1cf 100644 --- a/activerecord/lib/active_record/relation/batches.rb +++ b/activerecord/lib/active_record/relation/batches.rb @@ -20,8 +20,6 @@ module ActiveRecord find_in_batches(options) do |records| records.each { |record| yield record } end - - self end # Yields each batch of records that was found by the find +options+ as diff --git a/activerecord/test/cases/batches_test.rb b/activerecord/test/cases/batches_test.rb index 6620464d6a..50ddf6c757 100644 --- a/activerecord/test/cases/batches_test.rb +++ b/activerecord/test/cases/batches_test.rb @@ -18,6 +18,13 @@ class EachTest < ActiveRecord::TestCase end end + def test_each_should_not_return_query_chain_and_execcute_only_one_query + assert_queries(1) do + result = Post.find_each(:batch_size => 100000){ } + assert_nil result + end + end + def test_each_should_raise_if_select_is_set_without_id assert_raise(RuntimeError) do Post.find_each(:select => :title, :batch_size => 1) { |post| post } |