Skip to content

Commit 4cfaa22

Browse files
authored
Merge pull request rails#47869 from hachi8833/query_guides_order_desc
Doc: Add `:order` option for find_each docs to Query Guides [ci-skip]
2 parents 4c3ad53 + 8fb80ac commit 4cfaa22

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

guides/source/active_record_querying.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,16 @@ appropriate `:start` and `:finish` options on each worker.
475475
Overrides the application config to specify if an error should be raised when an
476476
order is present in the relation.
477477

478+
**`:order`**
479+
480+
Specifies the primary key order (can be `:asc` or `:desc`). Defaults to `:asc`.
481+
482+
```ruby
483+
Customer.find_each(order: :desc) do |customer|
484+
NewsMailer.weekly(customer).deliver_now
485+
end
486+
```
487+
478488
#### `find_in_batches`
479489

480490
The [`find_in_batches`][] method is similar to `find_each`, since both retrieve batches of records. The difference is that `find_in_batches` yields _batches_ to the block as an array of models, instead of individually. The following example will yield to the supplied block an array of up to 1000 customers at a time, with the final block containing any remaining customers:

0 commit comments

Comments
 (0)