diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-01-29 17:53:10 -0200 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-01-29 17:53:10 -0200 |
commit | fec1028d088294c30f568e46db3bbd054a9330ff (patch) | |
tree | 93ee044f18873c3daa3acf86d338c6785b95e54a /activerecord/lib/active_record/relation | |
parent | 2c964ac59194c340660986423b4aa93de447c37b (diff) | |
parent | 0aad463cfbe9853fd3a7ab0f8e4e0a34715fd62c (diff) | |
download | rails-fec1028d088294c30f568e46db3bbd054a9330ff.tar.gz rails-fec1028d088294c30f568e46db3bbd054a9330ff.tar.bz2 rails-fec1028d088294c30f568e46db3bbd054a9330ff.zip |
Merge pull request #13201 from marcandre/find_in_batch_enumerator
`find_in_batches` now returns an `Enumerator`
Conflicts:
activerecord/CHANGELOG.md
activerecord/lib/active_record/relation/batches.rb
Diffstat (limited to 'activerecord/lib/active_record/relation')
-rw-r--r-- | activerecord/lib/active_record/relation/batches.rb | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/relation/batches.rb b/activerecord/lib/active_record/relation/batches.rb index e98b4712f5..dfcfef2ad2 100644 --- a/activerecord/lib/active_record/relation/batches.rb +++ b/activerecord/lib/active_record/relation/batches.rb @@ -64,6 +64,14 @@ module ActiveRecord # group.each { |person| person.party_all_night! } # end # + # If you do not provide a block to #find_in_batches, it will return an Enumerator + # for chaining with other methods: + # + # Person.find_in_batches.with_index do |group, batch| + # puts "Processing group ##{batch}" + # group.each(&:recover_from_last_night!) + # end + # # To be yielded each record one by one, use #find_each instead. # # ==== Options @@ -88,6 +96,7 @@ module ActiveRecord # the batch sizes. def find_in_batches(options = {}) options.assert_valid_keys(:start, :batch_size) + return to_enum(:find_in_batches, options) unless block_given? relation = self |