aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation
diff options
context:
space:
mode:
authorJosh Kalderimis <josh.kalderimis@gmail.com>2010-05-09 12:24:25 +0300
committerJosé Valim <jose.valim@gmail.com>2010-05-09 13:14:47 +0300
commit231d7676f72947bae765b9bd885b134aaf949921 (patch)
tree1943fb3a2ed3818334d1cb2b6863a89b87b4db00 /activerecord/lib/active_record/relation
parent06eaf27fffbd4e24c038ea40ee8d118b5b4f04df (diff)
downloadrails-231d7676f72947bae765b9bd885b134aaf949921.tar.gz
rails-231d7676f72947bae765b9bd885b134aaf949921.tar.bz2
rails-231d7676f72947bae765b9bd885b134aaf949921.zip
corrected AR find_each and find_in_batches to raise when the user uses select but does not specify the primary key
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activerecord/lib/active_record/relation')
-rw-r--r--activerecord/lib/active_record/relation/batches.rb9
1 files changed, 8 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation/batches.rb b/activerecord/lib/active_record/relation/batches.rb
index 1c61e7d450..4649e3b376 100644
--- a/activerecord/lib/active_record/relation/batches.rb
+++ b/activerecord/lib/active_record/relation/batches.rb
@@ -67,11 +67,18 @@ 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
- records = relation.where(primary_key.gt(records.last.id)).all
+
+ 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
end
end