#34413: Variant of Prefetch but for the earliest/latest related object
-------------------------------------+-------------------------------------
     Reporter:  Willem Van Onsem     |                    Owner:  nobody
         Type:  New feature          |                   Status:  closed
    Component:  Database layer       |                  Version:  dev
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:  duplicate
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  1                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Gordon Wrigley):

 I would like to do singular prefetches, which seems kinda like what this
 is asking for.

 With regard to:
 {{{#!python
     User.objects.prefetch_related(
         Prefetch("groups", queryset=Group.objects.order_by('name')[:1],
 to_attr="first_group")
     )
 }}}

 The downside of this is "first_group" is actually a 1 element list. I was
 imagining maybe it could be just the item when there is a single item
 slice, or failing that a "flat=True" option on Prefetch.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34413#comment:10>
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/0107018953ebe464-449ef409-248b-4880-96bd-e6108b525eac-000000%40eu-central-1.amazonses.com.

Reply via email to