On Mon, Nov 17, 2008 at 10:46 AM, Randy Barlow <[EMAIL PROTECTED]> wrote: > > 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(). > > 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!
But that just means you'll need to explicitly set cascade on those models you *do* want to cascade delete. And, IMO, the vast majority of foreign key use cases do benefit from an auto cascading delete. For the specific Links/Groups example, personally I'd just do it with a many to many relation. It's entirely feasible that in the future, Links will need the ability to associate itself to multiple groups. For now, I'd just limit a link to one group via some custom validation. -- --- David Zhou [EMAIL PROTECTED] --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---