Bird
0
0

Which of the following is a correct way to prefetch a reverse relation named orders from a Customer model?

easy📝 Conceptual Q2 of 15
Django - Caching
Which of the following is a correct way to prefetch a reverse relation named orders from a Customer model?
ACustomer.objects.prefetch_related('orders')
BCustomer.objects.select_related('orders')
CCustomer.objects.filter(orders__isnull=False)
DCustomer.objects.annotate(orders)
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct method for reverse relation prefetching

    prefetch_related is used for reverse relations, not select_related.
  2. Step 2: Check syntax

    Using prefetch_related with the reverse relation name as a string is correct.
  3. Final Answer:

    Customer.objects.prefetch_related('orders') -> Option A
  4. Quick Check:

    Correct prefetch syntax = A [OK]
Quick Trick: Use prefetch_related with reverse relation name as string [OK]
Common Mistakes:
MISTAKES
  • Using select_related for reverse relations
  • Filtering instead of prefetching
  • Using annotate incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes