Django

Code

Changeset 7190

Show
Ignore:
Timestamp:
03/03/08 10:36:28 (4 months ago)
Author:
mtredinnick
Message:

queryset-refactor: Simplified updates of related tables, with added bonus of less bugs.

It will be slightly less efficient in rare cases, but who cares? If anybody
needs it to be as efficient as possible they can write the query manually and
this is good enough for the other 98% or so.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/queryset-refactor/django/db/models/sql/subqueries.py

    r7180 r7190  
    22Query subclasses which provide extra functionality beyond simple data retrieval. 
    33""" 
    4 from copy import deepcopy 
    54 
    65from django.contrib.contenttypes import generic 
     
    160159        # from other tables. 
    161160        query = self.clone(klass=Query) 
    162         main_alias = query.tables[0] 
    163         if count != 1: 
    164             query.unref_alias(main_alias) 
    165         if query.alias_map[main_alias][ALIAS_REFCOUNT]: 
    166             alias = '%s0' % self.alias_prefix 
    167             query.change_alias(main_alias, alias) 
    168             col = query.model._meta.pk.column 
    169         else: 
    170             for model in query.model._meta.get_parent_list(): 
    171                 for alias in query.table_map.get(model._meta.db_table, []): 
    172                     if query.alias_map[alias][ALIAS_REFCOUNT]: 
    173                         col = model._meta.pk.column 
    174                         break 
    175         query.add_local_columns([col]) 
     161        alias = '%s0' % self.alias_prefix 
     162        query.change_alias(query.tables[0], alias) 
     163        self.add_local_columns([query.model._meta.pk.column]) 
    176164 
    177165        # Now we adjust the current query: reset the where clause and get rid