#35309: Remove Order by on models when prefetching by id
-------------------------------------+-------------------------------------
     Reporter:  Laurent Lyaudet      |                    Owner:  nobody
         Type:                       |                   Status:  closed
  Cleanup/optimization               |
    Component:  Database layer       |                  Version:  5.0
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:  invalid
     Keywords:  prefetch order_by    |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

 * resolution:   => invalid
 * status:  new => closed

Comment:

 `Meta.ordering` is working as expected, please
 [https://docs.djangoproject.com/en/5.0/ref/models/options/#ordering refer
 to its documentation] and associated warning

 > Ordering is not a free operation. Each field you add to the ordering
 incurs a cost to your database. Each foreign key you add will implicitly
 include all of its default orderings as well.

 If you don't want this implicit behaviour then don't use `Meta.ordering`.
 If you want to keep using it but not for particular prefetches than use
 `Prefetch` objects with a queryset that explicitly calls `order_by()` to
 disable ordering.

 {{{#!python
 B.objects.prefetch_related(Prefetch("a", A.objects.order_by()))
 }}}
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35309#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018e449d29fd-40c001e8-74dd-4a3a-924e-0a2a190708ae-000000%40eu-central-1.amazonses.com.

Reply via email to