#7539: Add ON DELETE and ON UPDATE support to Django
---------------------------------------------------+------------------------
          Reporter:  glassfordm                    |         Owner:         
            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 emulbreh):

 Changes between 7539.on_delete.r11706.diff and 7539.on_delete.r11724.diff:

  *  Updated to work with m2m-refactor
  *  Moved `delete_objects()` inside `CollectedObjects`:
 `CollectedObjects.delete()`
  *  Got rid of `DeleteQuery.delete_batch_related()`: use the normal code
 path for m2m intermediary models. This is required to enable `on_delete`
 for foreign keys on intermediary models. But it results in a dramatical
 increase of `SELECT` queries. Therefore ..
  *  Moved `_collect_sub_objects()` to `CollectedObjects` and changed its
 algorithm to collect related objects in batches. This reduces the number
 of `SELECT` queries for related objects. The delete call in the following
 example requires a total of 103 queries in trunk, while the patch only
 requires 4 queries: related `C` instances will be looked up in one bulk
 query.
     {{{
     #!python

     class A(models.Model): pass

     class B(models.Model):
      a = models.ForeignKey(A)

     class C(models.Model):
      b = models.ForeignKey(B)

     a = A.objects.create()
     for i in xrange(100): B.objects.create(a=a)
     a.delete()

     }}}
  *  Introduced a batch (don't select, just delete) option to get rid of
 the one remaining extra query for `auto_created` intermediary models.
  *  Altered `collect()` to collect inheritance parents without additional
 queries.
  *  Moved `CollectedObjects` into its own module, as it now encapsulates
 the whole deletion logic and depends on `db.models.sql`.


 TODO:
  * There is an ugly `contrib.contenttypes` import in `subqueries.py`.
 Deleting generic relations should be handled by a custom `on_delete`
 handler instead.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/7539#comment:30>
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