#30894: Reverse OneToOneField relation: `prefetch_related` uses `related_name`
while `select_related` uses `related_query_name`
-------------------------------------+-------------------------------------
     Reporter:  Adam Sołtysik        |                    Owner:  nobody
         Type:                       |                   Status:  closed
  Cleanup/optimization               |
    Component:  Database layer       |                  Version:  2.2
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:  wontfix
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

 * component:  Documentation => Database layer (models, ORM)


Comment:

 Hey Simon. I'm happy if you want to reopen and Accept, but I'm not
 entirely sure it's the best change...

 `related_query_name` serves when to make filtering a little prettier where
 the `related_name` doesn't read right, i.e. you might want to write
 `...filter(tag__name='...')` rather that `...filter(tag_set__name='...')`
 (or `tags` being the example from the docs). That reads better because
 you're saying ''where the tag name is ...'', i.e. checking the property on
 the individual, rather than the set.

 But with `prefetch_related()`, you want to prefetch the set, so you want
 `prefetch_related('tag_set')` (or `tags`) — you **want** the
 `related_name`.

 (So if the issue is inconsistency, maybe it's `select_related` that has it
 backwards — via `get_related_name()`, but we can't change that now I'd
 guess...)

 Q: how does `get_prefetcher()` look if we're **not** retrieving the actual
 descriptor off of the model class?

 As I say, I leave to you. Thanks.

 (For my future ref c.f. #18668, #15962, ...)

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30894#comment:7>
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 django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.f10cde131f2ce14cbfa616285b290100%40djangoproject.com.

Reply via email to