#7539: Add ON DELETE and ON UPDATE support to Django
---------------------------------------------------+------------------------
          Reporter:  glassfordm                    |         Owner:  nobody 
            Status:  new                           |     Milestone:         
         Component:  Database layer (models, ORM)  |       Version:  SVN    
        Resolution:                                |      Keywords:  feature
             Stage:  Design decision needed        |     Has_patch:  1      
        Needs_docs:  1                             |   Needs_tests:  0      
Needs_better_patch:  0                             |  
---------------------------------------------------+------------------------
Comment (by benjaoming):

 Someone requested a discussion...

 I just had an encounter with this, and what I lacked was *knowing* what's
 going on with regards to cascading deletion, because it's quite dangerous
 (you loose data!!) and steals lots of time. Preventing it is simple,
 though. Overriding the delete() method of a model and calling clear() on
 the related model's foreign keys is simple, and it's a manual
 implementation, that all programmers should be able to understand.

 But I can think of another alternative: If null=True for the foreign key
 in question, why not automatically use SET NULL when the related instance
 is deleted? For me, this is even more "intuitive" than CASCADE. After all,
 null=True is something that the programmer specifies and has to deal with
 anywhere in the implementation, which is also why he doesn't need
 cascading deletion of such a relation.

 Also, if on_delete is possible to set in a key field, it would have to
 comply with the null option.. and together with the "intuition argument"
 that creates a 1:1 correspondence between the two options.

 And then the "logic argument": Django handles its logic in Python code,
 not in the Database, which is kept as a simple storage engine. The
 RESTRICT option is a validation issue, and will probably be handled this
 way in most cases, so having the database enforcing it, would be
 redundant. To enable it on model-level could pave the way for some nice
 new automatic validation in ModelForms, so I think it sounds like a nice
 feature.

 If all this is implemented, I would suggest to remove the null option from
 key fields and have it set according to on_delete.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/7539#comment:14>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to