I have a contact management system where I have "items" and "relationships". The relationship is the glue between items. It has two polymorphic belongs_to called parent and child that link to an item. An item can be a person, company, address, etc. The create side of things is beginning to firm up. I want to come up with an approach on how to do deletes. What I want to have happen is if you delete an item. Then all the relationships to that item need to be deleted as well. But, on top of that, if that leaves other items in the database that have no relation pointing to them, those need to be deleted. One thought is to start a transaction, do the delete of the first item. Then search and delete relations that are pointing to something that no longer exists. Then search and delete items that have nothing pointing to them. Then commit the transaction. Does anyone else have any suggestions?
on 2007-07-04 17:56