summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2010-04-30 16:32:48 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2010-04-30 16:32:48 +0000
commit8b1aebbf352cd2c7e0c3bd81b83553fe293ad56a (patch)
tree733d0ad2f5424482b68d40ebeaa9673621f1d452 /django
parent21d98c5ebdf7063aca8666255b31673e6af595c8 (diff)
Fixed #12851 -- Another attempt at fixing select_related() with inherited models, this time with only(). Thanks to phxx for the test case.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@13059 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
-rw-r--r--django/db/models/query.py12
-rw-r--r--django/db/models/sql/query.py4
2 files changed, 13 insertions, 3 deletions
diff --git a/django/db/models/query.py b/django/db/models/query.py
index dfb894930b..d9fbd9b8cb 100644
--- a/django/db/models/query.py
+++ b/django/db/models/query.py
@@ -1154,7 +1154,17 @@ def get_cached_row(klass, row, index_start, using, max_depth=0, cur_depth=0,
return None
restricted = requested is not None
- load_fields = only_load and only_load.get(klass) or None
+ if only_load:
+ load_fields = only_load.get(klass)
+ # When we create the object, we will also be creating populating
+ # all the parent classes, so traverse the parent classes looking
+ # for fields that must be included on load.
+ for parent in klass._meta.get_parent_list():
+ fields = only_load.get(parent)
+ if fields:
+ load_fields.update(fields)
+ else:
+ load_fields = None
if load_fields:
# Handle deferred fields.
skip = set()
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index 40faa545c8..0913399e2a 100644
--- a/django/db/models/sql/query.py
+++ b/django/db/models/sql/query.py
@@ -556,10 +556,10 @@ class Query(object):
# models.
workset = {}
for model, values in seen.iteritems():
- for field in model._meta.fields:
+ for field, m in model._meta.get_fields_with_model():
if field in values:
continue
- add_to_dict(workset, model, field)
+ add_to_dict(workset, m or model, field)
for model, values in must_include.iteritems():
# If we haven't included a model in workset, we don't add the
# corresponding must_include fields for that model, since an