#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
-------------------------------------+-------------------------------------
Comment (by Adam Sołtysik):
I think I should add a bit more about my exact use case. I have
`OneToOneField` with `_something` as `related_name` and `something` as
`related_query_name`, and I also have a property `something` that returns
`_something` if it exists, and a default object if it doesn't. This way
everywhere in my code I use only `something` without underscore -- except
for `prefetch_related()`, and it's even worse with chained relations, as I
end up with triple underscores, like
`prefetch_related(_something1___something2)`.
However, I've just a found another solution for the problem of missing
`OneToOneField`s: https://stackoverflow.com/a/32106815, which doesn't make
it necessary to use different `related_name` and `related_query_name`. I'm
going to test it, and if it works, then the issue will be lower priority
for me. Although I still think the two methods should work consistently.
--
Ticket URL: <https://code.djangoproject.com/ticket/30894#comment:8>
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 view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/065.824ac491b498a991125b0ac2855bfcc6%40djangoproject.com.