Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #11161 from dmitry/find_in_batches_works_without_l…

…ogger

ActiveRecord find_in_batches should work without logger

When I set logger to nil both methods from Batches module find_in_batches or find_each should work anyway.
  • Loading branch information...
commit 8f63515f6efbc5c342dc9af9aa936e72261a18fe 2 parents 5e6de39 + 1cf6871
@carlosantoniodasilva carlosantoniodasilva authored
View
4 activerecord/lib/active_record/relation/batches.rb
@@ -89,8 +89,8 @@ def find_in_batches(options = {})
relation = self
- unless arel.orders.blank? && arel.taken.blank?
- ActiveRecord::Base.logger.warn("Scoped order and limit are ignored, it's forced to be batch order and batch size")
+ if logger && (arel.orders.present? || arel.taken.present?)
+ logger.warn("Scoped order and limit are ignored, it's forced to be batch order and batch size")
end
start = options.delete(:start)
View
10 activerecord/test/cases/batches_test.rb
@@ -68,6 +68,16 @@ def test_warn_if_order_scope_is_set
Post.order("title").find_each { |post| post }
end
+ def test_logger_not_required
+ previous_logger = ActiveRecord::Base.logger
+ ActiveRecord::Base.logger = nil
+ assert_nothing_raised do
+ Post.limit(1).find_each { |post| post }
+ end
+ ensure
+ ActiveRecord::Base.logger = previous_logger
+ end
+
def test_find_in_batches_should_return_batches
assert_queries(@total + 1) do
Post.find_in_batches(:batch_size => 1) do |batch|
Please sign in to comment.
Something went wrong with that request. Please try again.