rails/rails — pull request #8073 by alexisbernard (2012-10-30 16:00:09+00:00)
Title: Fix find_in_batches against string IDs when start option is not specified

Hi,

Here is a fix for find_in_batches when Model#id is a string. In fact when calling find_in_batches (or find_each) without the start option it generates a wrong SQL statement:

Subscriber.find_each { |subscriber| ... }
# Generates SQL:
# SELECT "subscribers".* FROM "subscribers" WHERE ("subscribers"."nick" >= 0) ...

That statement is invalid with strict databases such as PostgreSQL, because it tries to compare a string against an integer.

With more tolerant databases such as SQLite it's passing, but in fact it skips IDs starting with a lower character than '0'.

Once accepted and merged, I plan to backport that fix in pull request #7987 for rails 3.2.

cc @spastorino