comma-csv/comma — pull request #92 by lackac (2014-10-20 10:03:39+00:00)
Title: Use :each for iterating when the scope has a limit or order clause

By default comma uses `ActiveRecord::Batches#find_each` for iterating over an `ActiveRecord::Relation` scope. This can cause unexpected behaviour when the scope it's being run on has a limit or order clause. Neither of those work with `#find_each`.

For example, `Book.limit(5).to_comma` would ignore the limit and export all books as CSV. Likewise, `Book.order(:pub_date).to_comma` would ignore the order clause in the scope and export the books in the order of their private keys.

My proposed solution checks whether there are limit or order clauses in the scope and in thoses cases uses the `:each` iterator instead of `:find_each`. It also emits a warning to the logs explaining that falling back to using `:each` might cause performance issues.