#29072: only()/defer() vs select_related()
-------------------------------------+-------------------------------------
               Reporter:  Дилян      |          Owner:  nobody
  Палаузов                           |
                   Type:  New        |         Status:  new
  feature                            |
              Component:  Database   |        Version:  master
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 Provided
 {{{
 class M(models.Model):
     n = models.IntegerField()
     r = models.IntegerField()
     t = models.IntegerField()
     s = models.IntegerField()
     u = models.IntegerField()

 class F(models.Model):
     g = models.ForeignKey(M, on_delete=models.CASCADE)
     a = models.IntegerField()
     b = models.IntegerField()
     c = models.IntegerField()
     d = models.IntegerField()
     e = models.IntegerField()
 }}}


 I want to obtain with a queryset all fields from F and M.n, but not the
 other fields of M like M.r.  This works
 {{{F.objects.select_related('g').defer('g__r', 'g__t', 'g__s', 'g__u')}}}
 but I don't like it, as I want to say only M.n has to be obtained, and not
 the others.  prefetch_related is also suboptimal, as it creates two SQL
 queries instead of one.  {{{only()}}} does not let me specify 'All fields
 of F'.

 {{{F.objects.select_related('g__n')}}} would fit from logic, but does not
 work ({{{django.core.exceptions.FieldError: Non-relational field given in
 select_related: 'n'. Choices are: (none)}}})

 Please make {{{select_related()}}} accept the above expression.

 This applies to both master and 1.11.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29072>
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/057.d931b9e46352a7da0f25ced76f329289%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to