Django

Code

Changeset 8128

Show
Ignore:
Timestamp:
07/27/08 20:32:46 (5 months ago)
Author:
mtredinnick
Message:

Fixed #7853 -- Fixed another case of deleting inherited models with foreign key
references. Thanks to Russell for the test case that demonstrated the problem.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/db/models/query.py

    r8100 r8128  
    836836 
    837837        update_query = sql.UpdateQuery(cls, connection) 
    838         for field in cls._meta.fields
     838        for field, model in cls._meta.get_fields_with_model()
    839839            if (field.rel and field.null and field.rel.to in seen_objs and 
    840840                    filter(lambda f: f.column == field.column, 
    841841                    field.rel.to._meta.fields)): 
    842                 update_query.clear_related(field, pk_list) 
     842                if model: 
     843                    sql.UpdateQuery(model, connection).clear_related(field, 
     844                            pk_list) 
     845                else: 
     846                    update_query.clear_related(field, pk_list) 
    843847 
    844848    # Now delete the actual data. 
  • django/trunk/tests/regressiontests/model_inheritance_regress/models.py

    r8061 r8128  
    5353    name = models.CharField(max_length=10) 
    5454 
     55class SelfRefParent(models.Model): 
     56    parent_data = models.IntegerField() 
     57    self_data = models.ForeignKey('self', null=True) 
    5558 
     59class SelfRefChild(SelfRefParent): 
     60    child_data = models.IntegerField() 
    5661 
    5762__test__ = {'API_TESTS':""" 
     
    183188[] 
    184189 
     190# Regression test for #7853 
     191# If the parent class has a self-referential link, make sure that any updates 
     192# to that link via the child update the right table. 
     193 
     194>>> obj = SelfRefChild.objects.create(child_data=37, parent_data=42) 
     195>>> obj.delete() 
     196 
    185197"""}