---
title: "Rails 5 adds finish option in find_in_batches"
description:
  "Rails 5 has an option to provide end value in find_in_batches method"
canonical_url: "https://www.bigbinary.com/blog/rails-5-provides-finish-option-for-find-in-batches"
markdown_url: "https://www.bigbinary.com/blog/rails-5-provides-finish-option-for-find-in-batches.md"
---

# Rails 5 adds finish option in find_in_batches

Rails 5 has an option to provide end value in find_in_batches method

- Author: Mohit Natoo
- Published: June 6, 2016
- Categories: Rails 5, Rails

In Rails 4.x we had `start` option in `find_in_batches` method.

```ruby

Person.find_in_batches(start: 1000, batch_size: 2000) do |group|
  group.each { |person| person.party_all_night! }
end

```

The above code provides batches of `Person` starting from record whose value of
primary key is equal to 1000.

There is no end value for primary key. That means in the above case all the
records that have primary key value greater than 1000 are fetched.

Rails 5 [introduces finish option](https://github.com/rails/rails/pull/12257)
that serves as an upper limit to the primary key value in the records being
fetched.

```ruby

Person.find_in_batches(start: 1000, finish: 9500, batch_size: 2000) do |group|
  group.each { |person| person.party_all_night! }
end

```

The above code ensures that no record in any of the batches has the primary key
value greater than 9500.

## Links

- [Human page](https://www.bigbinary.com/blog/rails-5-provides-finish-option-for-find-in-batches)
