Fixed #12851 -- Corrected the loading of values when select_related() is used on inherited models. Thanks to phxx for the report and test case.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@13054 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
1ff7ed2e69
commit
4e97d7f8e4
|
@ -556,7 +556,7 @@ class Query(object):
|
|||
# models.
|
||||
workset = {}
|
||||
for model, values in seen.iteritems():
|
||||
for field in model._meta.local_fields:
|
||||
for field in model._meta.fields:
|
||||
if field in values:
|
||||
continue
|
||||
add_to_dict(workset, model, field)
|
||||
|
|
|
@ -65,6 +65,9 @@ class Client(models.Model):
|
|||
state = models.ForeignKey(State, null=True)
|
||||
status = models.ForeignKey(ClientStatus)
|
||||
|
||||
class SpecialClient(Client):
|
||||
value = models.IntegerField()
|
||||
|
||||
# Some model inheritance exercises
|
||||
class Parent(models.Model):
|
||||
name = models.CharField(max_length=10)
|
||||
|
@ -170,8 +173,28 @@ Exercising select_related() with multi-table model inheritance.
|
|||
>>> wa = State.objects.create(name="Western Australia", country=australia)
|
||||
>>> _ = Client.objects.create(name='Brian Burke', state=wa, status=active)
|
||||
>>> burke = Client.objects.select_related('state').defer('state__name').get(name='Brian Burke')
|
||||
>>> burke.name
|
||||
u'Brian Burke'
|
||||
>>> burke.state.name
|
||||
u'Western Australia'
|
||||
|
||||
"""}
|
||||
# Still works if we're dealing with an inherited class
|
||||
>>> _ = SpecialClient.objects.create(name='Troy Buswell', state=wa, status=active, value=42)
|
||||
>>> troy = SpecialClient.objects.select_related('state').defer('state__name').get(name='Troy Buswell')
|
||||
>>> troy.name
|
||||
u'Troy Buswell'
|
||||
>>> troy.value
|
||||
42
|
||||
>>> troy.state.name
|
||||
u'Western Australia'
|
||||
|
||||
# Still works if we defer an attribute on the inherited class
|
||||
>>> troy = SpecialClient.objects.select_related('state').defer('value', 'state__name').get(name='Troy Buswell')
|
||||
>>> troy.name
|
||||
u'Troy Buswell'
|
||||
>>> troy.value
|
||||
42
|
||||
>>> troy.state.name
|
||||
u'Western Australia'
|
||||
|
||||
"""}
|
||||
|
|
Loading…
Reference in New Issue