Opened 18 years ago
Closed 17 years ago
#2465 closed enhancement (fixed)
Make select_related() related work for ForeignKeys with null=True
Reported by: | Owned by: | Malcolm Tredinnick | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | |
Severity: | normal | Keywords: | |
Cc: | mir@… | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
While trying to figure out why select_related() wasn't doing anything for me, I finally went to the source and realized that it is coded to not work when null=True is set on the relationship. This is something I think should be documented, so here's a patch. Hopefully I'm somewhat close on the markup, I don't know how to test it.
Attachments (1)
Change History (9)
by , 18 years ago
Attachment: | db-api.txt.diff added |
---|
comment:1 by , 18 years ago
Summary: | [patch] doc addition - select_related() and null=True → Make select_related() related work for ForeignKeys with null=True |
---|
comment:2 by , 18 years ago
No, I'd rather not change select_related
to work for null=True
fields. That would involve a bunch of LEFT JOIN
s in the resulting SQL. select_related
does not work on null=True
fields on purpose.
comment:3 by , 18 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:4 by , 17 years ago
Component: | Documentation → Database wrapper |
---|---|
Keywords: | qs-rf added |
Resolution: | fixed |
Status: | closed → reopened |
Reopening as this will be fairly easy to support when select_related() allows explicit field calls in queryset refactoring.
comment:5 by , 17 years ago
Owner: | changed from | to
---|---|
Status: | reopened → new |
comment:6 by , 17 years ago
Owner: | changed from | to
---|
comment:7 by , 17 years ago
Cc: | added |
---|
comment:8 by , 17 years ago
Keywords: | qs-rf removed |
---|---|
Resolution: | → fixed |
Status: | new → closed |
It would be better to fix select_related() to work properly. There is no real reason for it to be restricted like this. Just to confirm: are you seeing the problem with a ForeignKey field, or only with a ManyToManyField?