aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2010-05-09 12:30:45 +0100
committerPratik Naik <pratiknaik@gmail.com>2010-05-09 12:33:25 +0100
commitf75a6fec2947ce23bd3ca4911d2d798415ccd355 (patch)
tree5deb59e4f92058619145f5eb8a9c84a1873d4bfc /activerecord/lib
parent231d7676f72947bae765b9bd885b134aaf949921 (diff)
downloadrails-f75a6fec2947ce23bd3ca4911d2d798415ccd355.tar.gz
rails-f75a6fec2947ce23bd3ca4911d2d798415ccd355.tar.bz2
rails-f75a6fec2947ce23bd3ca4911d2d798415ccd355.zip
Improve code from 231d7676f72947bae765b9bd885b134aaf949921
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/relation/batches.rb12
1 files changed, 5 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/relation/batches.rb b/activerecord/lib/active_record/relation/batches.rb
index 4649e3b376..412be895c4 100644
--- a/activerecord/lib/active_record/relation/batches.rb
+++ b/activerecord/lib/active_record/relation/batches.rb
@@ -67,18 +67,16 @@ module ActiveRecord
relation = relation.except(:order).order(batch_order).limit(batch_size)
records = relation.where(primary_key.gteq(start)).all
- key_value = self.primary_key.name
-
while records.any?
yield records
break if records.size < batch_size
- last_value = records.last.send(key_value)
-
- raise "You must include the primary key if you define a select" unless last_value.present?
-
- records = relation.where(primary_key.gt(last_value)).all
+ if primary_key_offset = records.last.id
+ records = relation.where(primary_key.gt(primary_key_offset)).all
+ else
+ raise "Primary key not included in the custom select clause"
+ end
end
end