{{{#!python
class Chef(model.Model):
pass
class Restaurant(models.Model):
chef = models.ForeignKey(Chef)
class ItalianRestaurant(Restaurant):
pass
}}}
Then given `restaurant.chef` is cached accessing
`restaurant.italianrestaurant.chef` shouldn't incur an additional query.
e.g.
{{{#!python
chef = Chef.objects.create()
italian_restaurant = ItalianRestaurant.objects.create(chef=chef)
# A single query with two joins
restaurant = Restaurant.objects.select_related('chef',
'italianrestaurant').get(pk=italian_restaurant.pk)
assert restaurant.chef == chef # Currently no queries.
assert restaurant.italian_restaurant == italian_restaurant # Currently no
queries.
assert restaurant.italian_restaurant.chef is restaurant.chef # Currently
fails and performs a query.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28834>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Comment (by Simon Charette):
[https://github.com/django/django/pull/9380 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/28834#comment:1>
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/28834#comment:2>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/28834#comment:3>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"78c5e7b90eee10067d39a8ba6588e6b53ba00d82" 78c5e7b]:
{{{
#!CommitTicketReference repository=""
revision="78c5e7b90eee10067d39a8ba6588e6b53ba00d82"
Fixed #28834 -- Followed ancestor links on field cache lookup failure.
Thanks Tim for the review.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28834#comment:4>
Comment (by Tim Graham <timograham@…>):
In [changeset:"265506bbc347a6b3fcc6c66ab1a2417b3b7ea57a" 265506bb]:
{{{
#!CommitTicketReference repository=""
revision="265506bbc347a6b3fcc6c66ab1a2417b3b7ea57a"
Refs #28834 -- Moved ancestor field cached value fallback to related
fields descriptor.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28834#comment:5>