Forum: Ruby on Rails Delete help needed

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
3f38541776a2513a20ea2f1c2d522cb3?d=identicon&s=25 Perry Smith (pedz)
on 2007-07-04 17:56
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?
This topic is locked and can not be replied to.