#26780: Prefetch objects don't work with slices
-------------------------------------+-------------------------------------
     Reporter:  Ludwik Trammer       |                    Owner:  nobody
         Type:  New feature          |                   Status:  new
    Component:  Database layer       |                  Version:  master
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  prefetch, slicing    |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Haseeb Ahmad):

 I think there is a workaround now to in django new version as we have
 OuterRef and Subquery.

 from django.db.models import OuterRef, Subquery

 User.objects.all().prefetch_related('comments',
 queryset=Comment.objects.filter(id__in=Subquery(
 Comment.objects.filter(user_id=OuterRef('user_id')).values_list('id',
 flat=True)[:5])))

-- 
Ticket URL: <https://code.djangoproject.com/ticket/26780#comment:9>
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/064.f6e73cfbfac80f1ef25cbaa35c851185%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to