diff options
author | Alexander Balashov <divineforest@gmail.com> | 2013-03-28 16:03:02 +0400 |
---|---|---|
committer | Alexander Balashov <divineforest@gmail.com> | 2014-01-21 17:27:34 +0400 |
commit | 691709dd6741757e5c4459c8942857ee019b68a0 (patch) | |
tree | 72a5f1e23bea676973d37cbbb3d4d97b435e6dd6 /activerecord/lib | |
parent | b8302bcfdaec2a9e7658262d6feeb535c572922d (diff) | |
download | rails-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.rb | 7 |
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 |