Fixed #7270 -- Added the ability to follow reverse OneToOneFields in select_related(). Thanks to George Vilches, Ben Davis, and Alex Gaynor for their work on various stages of this patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12307 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Russell Keith-Magee 2010-01-27 13:30:29 +00:00
parent 8e8d4b5888
commit 58cd220f51
9 changed files with 306 additions and 14 deletions

View file

@ -619,17 +619,29 @@ This is also valid::
...and would also pull in the ``building`` relation.
You can only refer to ``ForeignKey`` relations in the list of fields passed to
``select_related``. You *can* refer to foreign keys that have ``null=True``
(unlike the default ``select_related()`` call). It's an error to use both a
list of fields and the ``depth`` parameter in the same ``select_related()``
call, since they are conflicting options.
You can refer to any ``ForeignKey`` or ``OneToOneField`` relation in
the list of fields passed to ``select_related``. Ths includes foreign
keys that have ``null=True`` (unlike the default ``select_related()``
call). It's an error to use both a list of fields and the ``depth``
parameter in the same ``select_related()`` call, since they are
conflicting options.
.. versionadded:: 1.0
Both the ``depth`` argument and the ability to specify field names in the call
to ``select_related()`` are new in Django version 1.0.
.. versionchanged:: 1.2
You can also refer to the reverse direction of a ``OneToOneFields`` in
the list of fields passed to ``select_related`` -- that is, you can traverse
a ``OneToOneField`` back to the object on which the field is defined. Instead
of specifying the field name, use the ``related_name`` for the field on the
related object.
``OneToOneFields`` will not be traversed in the reverse direction if you
are performing a depth-based ``select_related``.
.. _queryset-extra:
``extra(select=None, where=None, params=None, tables=None, order_by=None, select_params=None)``
@ -1335,7 +1347,7 @@ extract two field values, where only one is expected::
entries = Entry.objects.filter(blog__in=list(values))
Note the ``list()`` call around the Blog ``QuerySet`` to force execution of
the first query. Without it, a nested query would be executed, because
the first query. Without it, a nested query would be executed, because
:ref:`querysets-are-lazy`.
gt