diff options
| author | Jacob Kaplan-Moss <jacob@jacobian.org> | 2007-02-28 15:24:05 +0000 |
|---|---|---|
| committer | Jacob Kaplan-Moss <jacob@jacobian.org> | 2007-02-28 15:24:05 +0000 |
| commit | 4477f50f0b346f6c5f177a4bad99041a9b903842 (patch) | |
| tree | 0d031c6e9ba1bcacde77bbb7594a07baadac2c8e /docs | |
| parent | 9c67c1dd8d6d19872af041b7d79c0c688b19b416 (diff) | |
Added a "depth" argument to select_related() to control how many "levels" of relations select_related() is willing to follow (refs #3275).
Also added unit tests for select_related().
git-svn-id: http://code.djangoproject.com/svn/django/trunk@4645 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/db-api.txt | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/docs/db-api.txt b/docs/db-api.txt index 3dc0efbabd..5cb5e4c983 100644 --- a/docs/db-api.txt +++ b/docs/db-api.txt @@ -596,6 +596,19 @@ related ``Person`` *and* the related ``City``:: Note that ``select_related()`` does not follow foreign keys that have ``null=True``. +Usually, using ``select_related()`` can vastly improve performance since your +app can avoid many database calls. However, in situations with deeply nested +sets of relationships ``select_related()`` can sometimes end up following "too +many" relations, and can generate queries so large that they end up being slow. + +In these situations, you can use the ``depth`` argument to ``select_related()`` +to control how many "levels" of relations ``select_related()`` will actually +follow:: + + b = Book.objects.select_related(depth=1).get(id=4) + p = b.author # Doesn't hit the database. + c = p.hometown # Requires a database call. + ``extra(select=None, where=None, params=None, tables=None)`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
