summaryrefslogtreecommitdiff
path: root/django/db/models/options.py
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-06-29 02:36:18 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-06-29 02:36:18 +0000
commitbb2182453b49157fb6fba4de6d3c53a09f73d74b (patch)
tree502104407d15efb2dadabd30d95e71b9ede44a34 /django/db/models/options.py
parentd800c0b031aea81ee6f3a7c28ef88c05494e4eea (diff)
Fixed handling of multiple fields in a model pointing to the same related model.
Thanks to ElliotM, mk and oyvind for some excellent test cases for this. Fixed #7110, #7125. git-svn-id: http://code.djangoproject.com/svn/django/trunk@7778 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/models/options.py')
-rw-r--r--django/db/models/options.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/django/db/models/options.py b/django/db/models/options.py
index e5b30b4746..a81a34d722 100644
--- a/django/db/models/options.py
+++ b/django/db/models/options.py
@@ -44,6 +44,7 @@ class Options(object):
self.one_to_one_field = None
self.abstract = False
self.parents = SortedDict()
+ self.duplicate_targets = {}
def contribute_to_class(self, cls, name):
from django.db import connection
@@ -115,6 +116,24 @@ class Options(object):
auto_created=True)
model.add_to_class('id', auto)
+ # Determine any sets of fields that are pointing to the same targets
+ # (e.g. two ForeignKeys to the same remote model). The query
+ # construction code needs to know this. At the end of this,
+ # self.duplicate_targets will map each duplicate field column to the
+ # columns it duplicates.
+ collections = {}
+ for column, target in self.duplicate_targets.iteritems():
+ try:
+ collections[target].add(column)
+ except KeyError:
+ collections[target] = set([column])
+ self.duplicate_targets = {}
+ for elt in collections.itervalues():
+ if len(elt) == 1:
+ continue
+ for column in elt:
+ self.duplicate_targets[column] = elt.difference(set([column]))
+
def add_field(self, field):
# Insert the given field in the order in which it was created, using
# the "creation_counter" attribute of the field.