Richard Sandilands
2006-Nov-04 02:22 UTC
[Rails] Model.delete_all vs Model.destroy_all in a habtm
Hi there I have an habtm association between 2 Models. I regularly have to truncate the table on one side of the relationship and repopulate the table with a fresh csv file. I notice that f I do Model.delete_all, none of the records in my habtm join table get deleted, whereas if I use destroy_all they do. However, the overhead of using destroy_all is too great. For the amount of records I have to deal with, destroy_all is very processor and time intensive. How best to quickly truncate one side of the habtm relationship *and* the intermediate join table? I suppose I can drop to connection.execute and truncate that way, but that does not seem very Rails like. Any clues appreciated. Richard