aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorSantiago Pastorino <santiago@wyeworks.com>2012-09-21 19:10:16 -0300
committerSantiago Pastorino <santiago@wyeworks.com>2012-09-21 19:14:17 -0300
commiteb876c4d07130f15be2cac7be968cc393f959c62 (patch)
tree04914044df46ba84862b381052d025d2d7f1ac73 /activerecord/lib/active_record
parent008eaebb562af7d95907b46e3d734312c795b2e0 (diff)
downloadrails-eb876c4d07130f15be2cac7be968cc393f959c62.tar.gz
rails-eb876c4d07130f15be2cac7be968cc393f959c62.tar.bz2
rails-eb876c4d07130f15be2cac7be968cc393f959c62.zip
Revert "Fix find_in_batches with customized primary_key"
This reverts commit 761bc751d31c22e2c2fdae2b4cdd435b68b6d783. This commit wasn't fixing any issue just using the same table for different models with different primary keys.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/relation/batches.rb13
1 files changed, 6 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/relation/batches.rb b/activerecord/lib/active_record/relation/batches.rb
index d32048cce1..4d14506965 100644
--- a/activerecord/lib/active_record/relation/batches.rb
+++ b/activerecord/lib/active_record/relation/batches.rb
@@ -36,12 +36,12 @@ module ActiveRecord
# want multiple workers dealing with the same processing queue. You can
# make worker 1 handle all the records between id 0 and 10,000 and
# worker 2 handle from 10,000 and beyond (by setting the +:start+
- # option on that worker). You can also use non-integer-based primary keys
- # if start point is set.
+ # option on that worker).
#
# It's not possible to set the order. That is automatically set to
- # ascending on the primary key (e.g. "id ASC") to make the batch ordering
- # work. You can't set the limit either, that's used to control
+ # ascending on the primary key ("id ASC") to make the batch ordering
+ # work. This also mean that this method only works with integer-based
+ # primary keys. You can't set the limit either, that's used to control
# the batch sizes.
#
# Person.where("age > 21").find_in_batches do |group|
@@ -62,8 +62,7 @@ module ActiveRecord
ActiveRecord::Base.logger.warn("Scoped order and limit are ignored, it's forced to be batch order and batch size")
end
- start = options.delete(:start)
- start ||= 0
+ start = options.delete(:start).to_i
batch_size = options.delete(:batch_size) || 1000
relation = relation.reorder(batch_order).limit(batch_size)
@@ -71,7 +70,7 @@ module ActiveRecord
while records.any?
records_size = records.size
- primary_key_offset = records.last.send(primary_key)
+ primary_key_offset = records.last.id
yield records