﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
7246	select_related doesn't join parent chain for ForeignKeys on inherited models	Ivan Sagalaev <Maniac@…>	Jacob	"Given this model where Pizza refers to ItalianRestaurant which is inherited from Restaurant:

{{{
class Restaurant(models.Model):
    # ...

class ItalianRestaurant(Restaurant):
    # ...

class Pizza(models.Model):
    restaurant = models.ForeignKey(ItalianRestaurant)
}}}

Queries to Pizza with select_related don't join Restaurant table and try to attach its fields to ItalianRestaurant table instead. Which results in wrong SQL.

Patch with tests follows. Though I believe that the patch is correct, logic of fill_related_selections seems to play on coincidental similarities between parent links and ordinary links and it may be better to refactor those into separate code paths. But I didn't penetrate it deep enough to do it."		closed	Database layer (models, ORM)	dev		fixed	qsrf-cleanup select_related inheritance	Malcolm Tredinnick	Accepted	1	0	0	0	0	0
