UUIDs (Universally unique identifiers) are really neat as IDs, and they allow you to have the ID of a model before it is even saved and guarantee that it won’t be fail insertion due to the ID being taken already. They’re also a full class type in PostgreSQL which is even more badass because it will handle the storage part, meaning you don’t have the drag on performance that would come along if you had just placed the UUID in a varchar (or equivelent).
When you try to use UUIDs with Rails, things fall apart with
#find_in_batches because its implementation abuses value comparisons
to get a performance benefit when paging through results (source).
We started using UUIDs on a few models, so I wrote a new version of
#find_in_batches that can work with either type of ID (but does not support the :start option).
This also fixes #find_each because #find_each uses #find_in_batches under the covers.
I figured it’d be useful to someone eventually, so here’s the code:
and in config/initializers/clean_find_in_batches.rb