소스 검색

Fixed #30355 -- Doc'd interaction between custom managers and prefetch_related().

Akash Kumar Sen 1 년 전
부모
커밋
5f2308710b
1개의 변경된 파일12개의 추가작업 그리고 0개의 파일을 삭제
  1. 12 0
      docs/topics/db/queries.txt

+ 12 - 0
docs/topics/db/queries.txt

@@ -1790,6 +1790,18 @@ methods::
 
     b.entry_set(manager="entries").is_published()
 
+.. admonition:: Interaction with prefetching
+
+    When calling :meth:`~django.db.models.query.QuerySet.prefetch_related` with
+    a reverse relation, the default manager will be used. If you want to
+    prefetch related objects using a custom reverse manager, use
+    :class:`Prefetch() <django.db.models.Prefetch>`. For example::
+
+        from django.db.models import Prefetch
+
+        prefetch_manager = Prefetch("entry_set", queryset=Entry.entries.all())
+        Blog.objects.prefetch_related(prefetch_manager)
+
 Additional methods to handle related objects
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~