#14371: Select related and parents
------------------------------------------+---------------------------------
Reporter: vzima | Owner: nobody
Status: new | Milestone:
Component: Database layer (models, ORM) | Version: 1.2
Keywords: | Stage: Unreviewed
Has_patch: 0 |
------------------------------------------+---------------------------------
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
}}}
--
Ticket URL: <http://code.djangoproject.com/ticket/14371>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.