summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorLoic Bistuer <loic.bistuer@sixmedia.com>2014-01-17 01:24:39 +0700
committerAnssi Kääriäinen <akaariai@gmail.com>2014-03-03 21:35:19 +0200
commit7bbb6958dcb6a450f926e5bb49b07391f801aef1 (patch)
tree54142821f5dcd252cc96b4784ae26be9eb48435d /docs
parentc8d61fa109b5a4dee1eb6f7ae62c1e6ac00c2cab (diff)
Allowed custom querysets when prefetching single valued relations
The original patch for custom prefetches didn't allow usage of custom queryset for single valued relations (along ForeignKey or OneToOneKey). Allowing these enables calling performance oriented queryset methods like select_related or defer/only. Thanks @akaariai and @timgraham for the reviews. Refs #17001.
Diffstat (limited to 'docs')
-rw-r--r--docs/ref/models/querysets.txt18
1 files changed, 18 insertions, 0 deletions
diff --git a/docs/ref/models/querysets.txt b/docs/ref/models/querysets.txt
index a160587953..22ccda4b8e 100644
--- a/docs/ref/models/querysets.txt
+++ b/docs/ref/models/querysets.txt
@@ -989,6 +989,24 @@ less ambiguous than storing a filtered result in the related manager's cache:
... Prefetch('pizzas', queryset=queryset))
>>> vegetarian_pizzas = restaurants[0].pizzas.all()
+Custom prefetching also works with single related relations like
+forward ``ForeignKey`` or ``OneToOneField``. Generally you'll want to use
+:meth:`select_related()` for these relations, but there are a number of cases
+where prefetching with a custom ``QuerySet`` is useful:
+
+* You want to use a ``QuerySet`` that performs further prefetching
+ on related models.
+
+* You want to prefetch only a subset of the related objects.
+
+* You want to use performance optimization techniques like
+ :meth:`deferred fields <defer()>`:
+
+ >>> queryset = Pizza.objects.only('name')
+ >>>
+ >>> restaurants = Restaurant.objects.prefetch_related(
+ ... Prefetch('best_pizza', queryset=queryset))
+
.. note::
The ordering of lookups matters.