#28834 closed Cleanup/optimization (fixed)
Fields cache should attempt to follow ancestor links on lookup failures
Reported by: | Simon Charette | Owned by: | Simon Charette |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Given the following models
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.
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.
Change History (5)
comment:1 by , 7 years ago
comment:2 by , 7 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:3 by , 7 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
Note:
See TracTickets
for help on using tickets.
PR