Permalink
Browse files

Improve code from 231d767

  • Loading branch information...
1 parent 231d767 commit f75a6fec2947ce23bd3ca4911d2d798415ccd355 @lifo lifo committed May 9, 2010
Showing with 5 additions and 7 deletions.
  1. +5 −7 activerecord/lib/active_record/relation/batches.rb
View
12 activerecord/lib/active_record/relation/batches.rb
@@ -67,18 +67,16 @@ def find_in_batches(options = {})
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
@carlosantoniodasilva
carlosantoniodasilva May 10, 2010

Should it use the primary key in record.last, instead of the :id call?

@josevalim
josevalim May 10, 2010

I'D always return the primary key value (at least it should)!

@josevalim
josevalim May 10, 2010

Grrrrrr, I meant 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

0 comments on commit f75a6fe

Please sign in to comment.