Message info
 
To:Django developers From:Yo-Yo Ma Subject:Could prefetch_related be modified to utilize select_related for ForeignKey relations? Date:Sun, 19 Feb 2012 14:18:20 -0800 (PST)
 

Speaking with regards to the ORM method documented at
https://docs.djangoproject.com/en/dev/ref/models/querysets/#prefetch-related

Of course, ``prefetch_related`` uses a Pythonic join to attach reverse-
related objects and avoids the N+1 queries problem, which of course is
great. However, if you use it like this:

>>> Restaurant.objects.prefetch_related('best_pizza__toppings__topping_type')

It doesn't seem to take advantage ``select_related`` (assuming that
``topping_type`` is a ``ForeignKey`` from ``Topping``. It instead
sends a separate query for ``Topping`` and ``ToppingType``, joining
them in Python. Is it feasible to modify ``prefetch_related`` use
``select_related`` when it encounters a ``ForeignKey``?

--
You received this message because you are subscribed to the Google Groups "Django developers" group.
To post to this group, send email to django-developers@googlegroups.com.
To unsubscribe from this group, send email to django-developers+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.