aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorAlexander Balashov <divineforest@gmail.com>2013-03-28 16:03:02 +0400
committerAlexander Balashov <divineforest@gmail.com>2014-01-21 17:27:34 +0400
commit691709dd6741757e5c4459c8942857ee019b68a0 (patch)
tree72a5f1e23bea676973d37cbbb3d4d97b435e6dd6 /activerecord/lib
parentb8302bcfdaec2a9e7658262d6feeb535c572922d (diff)
downloadrails-691709dd6741757e5c4459c8942857ee019b68a0.tar.gz
rails-691709dd6741757e5c4459c8942857ee019b68a0.tar.bz2
rails-691709dd6741757e5c4459c8942857ee019b68a0.zip
Fail early with "Primary key not included in the custom select clause" in find_in_batches
Before this patch find_in_batches raises this error only on second iteration. So you will know about the problem only when you get the batch size threshold.
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/relation/batches.rb7
1 files changed, 2 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/relation/batches.rb b/activerecord/lib/active_record/relation/batches.rb
index 49b01909c6..f02e2365f7 100644
--- a/activerecord/lib/active_record/relation/batches.rb
+++ b/activerecord/lib/active_record/relation/batches.rb
@@ -102,16 +102,13 @@ module ActiveRecord
while records.any?
records_size = records.size
primary_key_offset = records.last.id
+ raise "Primary key not included in the custom select clause" unless primary_key_offset
yield records
break if records_size < batch_size
- if primary_key_offset
- records = relation.where(table[primary_key].gt(primary_key_offset)).to_a
- else
- raise "Primary key not included in the custom select clause"
- end
+ records = relation.where(table[primary_key].gt(primary_key_offset)).to_a
end
end