mirror of https://github.com/django/django.git
Fixed #24048 -- Corrected QuerySet.only() docs about interaction with defer().
This commit is contained in:
parent
514884e9a5
commit
68bd8f4cb4
|
@ -1707,9 +1707,11 @@ one, doing so will result in an error.
|
||||||
|
|
||||||
.. method:: only(*fields)
|
.. method:: only(*fields)
|
||||||
|
|
||||||
The ``only()`` method is more or less the opposite of :meth:`defer()`. You call
|
The ``only()`` method is essentially the opposite of :meth:`defer`. Only the
|
||||||
it with the fields that should *not* be deferred when retrieving a model. If
|
fields passed into this method and that are *not* already specified as deferred
|
||||||
you have a model where almost all the fields need to be deferred, using
|
are loaded immediately when the queryset is evaluated.
|
||||||
|
|
||||||
|
If you have a model where almost all the fields need to be deferred, using
|
||||||
``only()`` to specify the complementary set of fields can result in simpler
|
``only()`` to specify the complementary set of fields can result in simpler
|
||||||
code.
|
code.
|
||||||
|
|
||||||
|
@ -1734,8 +1736,7 @@ logically::
|
||||||
# Final result is that everything except "headline" is deferred.
|
# Final result is that everything except "headline" is deferred.
|
||||||
Entry.objects.only("headline", "body").defer("body")
|
Entry.objects.only("headline", "body").defer("body")
|
||||||
|
|
||||||
# Final result loads headline and body immediately (only() replaces any
|
# Final result loads headline immediately.
|
||||||
# existing set of fields).
|
|
||||||
Entry.objects.defer("body").only("headline", "body")
|
Entry.objects.defer("body").only("headline", "body")
|
||||||
|
|
||||||
All of the cautions in the note for the :meth:`defer` documentation apply to
|
All of the cautions in the note for the :meth:`defer` documentation apply to
|
||||||
|
@ -1756,6 +1757,11 @@ are in your ``only()`` call.
|
||||||
deferred fields, only the loaded fields will be saved. See
|
deferred fields, only the loaded fields will be saved. See
|
||||||
:meth:`~django.db.models.Model.save()` for more details.
|
:meth:`~django.db.models.Model.save()` for more details.
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
|
||||||
|
When using :meth:`defer` after ``only()`` the fields in :meth:`defer` will
|
||||||
|
override ``only()`` for fields that are listed in both.
|
||||||
|
|
||||||
``using()``
|
``using()``
|
||||||
~~~~~~~~~~~
|
~~~~~~~~~~~
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue