Commit 2eb832a7 authored by Russell Keith-Magee's avatar Russell Keith-Magee
Browse files

[1.1.X] Fixed #12851 -- Corrected the loading of values when select_related()...

[1.1.X] Fixed #12851 -- Corrected the loading of values when select_related() is used on inherited models. Thanks to phxx for the report and test case.

Backport of r13054 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@13055 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent 6f4563ac
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -621,7 +621,7 @@ class BaseQuery(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)
+24 −1
Original line number Diff line number Diff line
@@ -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'

"""}