6 ms·
Can you use find_in_batches or find_each with UUIDs?
by scotth 13y ago
Can you use find_in_batches or find_each with UUIDs?
- pg_bot 13y agoOf course, both of those methods are members of ActiveRecord and will work regardless of how you filter your records.
- ryeguy 13y agoBut don't those methods rely on the sequential ordering of auto incrementing ids?
- pg_bot 13y agoAfter reading the documentation more clearly. http://edgeapi.rubyonrails.org/classes/ActiveRecord/Batches.html http://edgeapi.rubyonrails.org/classes/ActiveRecord/Batches..... It looks like there may need to be a patch for this feature, however the batching process forces the database to make a query in Ascending order for the primary keys so as long as you can generate new UUIDS in ascending order you should be fine. However problems look like they will occur if you generate a new record that has a UUID that would be inserted randomly between two numbers in the UUID range. I will see if I can bang something out and issue a pull request.
- w-ll 13y agoI was dealing with a similar issue on a project that all id's are UUID's because I wanted non-sequential id's. I found it was just as simple of selecting ranges based of their date_created attribute.
- dickeytk 13y agoNo because ActiveRecord will try and do > uuid comparisons that won't evaluate. Also, if it's not sequential, you may miss records while iterating through a collection.