Rails 6.1 now supports ORDER BY id for ActiveRecord batch processing methods like find_each, find_in_batches, and in_batches. This would allow us to retrieve the records in ascending or descending order of ID.
Points to remember:
- The ORDER BY clause only works with the primary key column.
- Valid values for the ORDER BY clause are [:asc,:desc] and it’s case sensitive.
- If we use caps or title case (like DESC or Asc) then we’ll get an ArgumentError.
Top comments (0)