Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Can you use find_in_batches or find_each with UUIDs?


Of course, both of those methods are members of ActiveRecord and will work regardless of how you filter your records.


But don't those methods rely on the sequential ordering of auto incrementing ids?


After reading the documentation more clearly. 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.


I 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.


No 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: