Feb

25

More of a note to self, but others may benefit.
Keep in mind when doing a delete_all on your model to empty the table, that you may want to reset the auto_increment value if you are using mySQL. Reason being, if you are completely reloading data into a table, you may have legacy bookmarked links that rely on your id(s).

Let’s say you are loading some job postings from an RSS feed. You may want to delete all records each time you reload the data just to make sure you are getting any edits to any records. But, your auto_increment will increase with each reload which will break links people may have referenced prior to your reload. In order to reset the auto_increment, simply issue the raw SQL command like so:

Career.delete_all
Career.connection.execute(’ALTER TABLE careers AUTO_INCREMENT = 0′)


I’ll have to look into the delete_all method in ActiveRecord and see if I can apply a patch that accepts a conditional to auto reset the auto_increment value.

Linkroll

Recent Projects