From e6f0e324e28bc7d0c125415de871466aa1f4b983 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Mon, 29 Jan 2018 10:12:58 -0500 Subject: [PATCH] Fixed #29081 -- Clarified comments in QuerySet.select_related() example. --- docs/ref/models/querysets.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/ref/models/querysets.txt b/docs/ref/models/querysets.txt index 10251efc72..c3395e9c9a 100644 --- a/docs/ref/models/querysets.txt +++ b/docs/ref/models/querysets.txt @@ -935,11 +935,13 @@ following models:: ... then a call to ``Book.objects.select_related('author__hometown').get(id=4)`` will cache the related ``Person`` *and* the related ``City``:: + # Hits the database with joins to the author and hometown tables. b = Book.objects.select_related('author__hometown').get(id=4) p = b.author # Doesn't hit the database. c = p.hometown # Doesn't hit the database. - b = Book.objects.get(id=4) # No select_related() in this example. + # Without select_related()... + b = Book.objects.get(id=4) # Hits the database. p = b.author # Hits the database. c = p.hometown # Hits the database.