#17003: prefetch_related should support foreign keys/one-to-one
-------------------------------------+-------------------------------------
     Reporter:  lukeplant            |                    Owner:  nobody
         Type:  New feature          |                   Status:  new
    Component:  Database layer       |                  Version:  1.3
  (models, ORM)                      |               Resolution:
     Severity:  Normal               |             Triage Stage:  Accepted
     Keywords:                       |      Needs documentation:  0
    Has patch:  0                    |  Patch needs improvement:  0
  Needs tests:  0                    |                    UI/UX:  0
Easy pickings:  0                    |
-------------------------------------+-------------------------------------

Comment (by lukeplant):

 I've added an implementation that appears to work, and addresses all the
 requirements set out above, and has support for `GenericForeignKey`.

 The 'API' for finding objects that support prefetching has now increased a
 bit:

 * we first look on descriptor objects themselves for the
 `get_prefetch_query_set` method.
 * the return value has expanded a bit:
   * to indicate singly related objects, which are a bit treated
 differently
   * to indicate the cache name, so that singly related objects can be set
 up correctly
   * to allow a more powerful method of finding the 'join values', the
 'attributes' that are returned can be callables - this is needed by
 `GenericForeignKey`.
 * also, for the singly related case, if the descriptor has the
 `get_prefetch_query_set()` method, it also must have an `is_cached()`
 method so that we can find out if the objects have already been fetched
 (e.g. by select_related).

 Docs have also been significantly re-written, since prefetch_related would
 now be an alternative to select_related for FK and one-to-one
 relationships.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/17003#comment:2>
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 post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to