﻿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
14371	Select related and parents	Vlastimil Zíma	nobody	"I have a parent model for multiple children, but has nothing but AutoField. I found out, that it is impossible to fill parent cache in queries.

Example:
{{{
class Parent(models.Model)
  pass

class Child(Parent)
  some_int = models.IntegerField()
}}}

{{{
>>> Child.objects.get(pk = 3).__dict__
{'_state': <django.db.models.base.ModelState object at 0x8eb19ac>,
 'id': 3,
 'some_int': 0,
 'parent_ptr_id': 3}

>>> Child.objects.select_related('parent').get(pk = 3).__dict__
{'_state': <django.db.models.base.ModelState object at 0x8eb19ac>,
 'id': 3,
 'some_int': 0,
 'parent_ptr_id': 3}
}}}

This also causes senseless SQLs when reaching parent from child ({{{child.parent_ptr}}}):
{{{
SELECT ""myapp_parent"".""id"" FROM ""myapp_parent"" WHERE ""myapp_parent"".""id"" = 3;
}}}

So far only workaround I found is:
{{{
child = Parent.objects.select_related('child').get(pk = 3).child
}}}"		closed	Database layer (models, ORM)	1.2		worksforme			Unreviewed	0	0	0	0	0	0
