#36764: QuerySet.only() causes n+1 queries with reverse foreign key relation
-------------------------------------+-------------------------------------
     Reporter:  bernhard             |                    Owner:  (none)
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  dev
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  queryset, only,      |             Triage Stage:
  defered                            |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Comment (by Clifford Gama):

 FWIW, this works:
 {{{#!python
     def test_only_reverse_fk(self):
         qs = self.s1.primary_set.only("name", "related_id")
         with self.assertNumQueries(1):
             for primary in qs:
                 primary.name
 }}}

 and so does `.values("name")`.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36764#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 visit 
https://groups.google.com/d/msgid/django-updates/0107019adf075f1d-5a85845c-aa0c-43ef-b744-583db4a25def-000000%40eu-central-1.amazonses.com.

Reply via email to