On Sun, 16 Nov 2008 23:21:05 -0800 (PST), Merrick <[EMAIL PROTECTED]> declared: > I have two models, links and groups. A Link has an optional foreign > key Group. > > When I delete a Group, Django by default deletes all Links that > referenced the Group that is being deleted. > > How do I avoid the default behavior that does a cascade delete. Of > course I could use the cursor but would am hoping there is some option > I don't know of for delete().
Funny that you ask this question, because I just spent two days undoing the Django cascading delete on my end. If you look at the delete() method in the Django code, it only makes three calls. The first two gather a list of all the objects that Django wants to delete. Basically, I wrote a new delete() method that iterates through those objects, finds all the references to the object that you want to delete and sets them to null. It then saves them. After this, you need to run those first two lines again to regather the objects you want to delete (this time, only the one object should appear), and then you can finally delete them. I would argue this is more desireable than using clear() explicitly, because you don't have to know anything about your models with this method. Any time you have to remember to set a certain relationship to null, you are bound to forget about another relationship between your objects, and you'll get cascading delete on something you didn't expect, and you won't have even noticed that it happened! -- Randy Barlow http://electronsweatshop.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---

