Opened 18 years ago

Closed 17 years ago

#2465 closed enhancement (fixed)

Make select_related() related work for ForeignKeys with null=True

Reported by: Adam Endicott <leftwing17@…> 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)

db-api.txt.diff (481 bytes ) - added by Adam Endicott <leftwing17@…> 18 years ago.

Download all attachments as: .zip

Change History (9)

by Adam Endicott <leftwing17@…>, 18 years ago

Attachment: db-api.txt.diff added

comment:1 by Malcolm Tredinnick, 18 years ago

Summary: [patch] doc addition - select_related() and null=TrueMake select_related() related work for ForeignKeys with null=True

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?

comment:2 by Adrian Holovaty, 18 years ago

No, I'd rather not change select_related to work for null=True fields. That would involve a bunch of LEFT JOINs in the resulting SQL. select_related does not work on null=True fields on purpose.

comment:3 by Adrian Holovaty, 18 years ago

Resolution: fixed
Status: newclosed

(In [3511]) Fixed #2465 -- Documented the fact that select_related doesn't follow null=True

comment:4 by David Cramer, 17 years ago

Component: DocumentationDatabase wrapper
Keywords: qs-rf added
Resolution: fixed
Status: closedreopened

Reopening as this will be fairly easy to support when select_related() allows explicit field calls in queryset refactoring.

comment:5 by Jacob, 17 years ago

Owner: changed from Jacob to malcolm
Status: reopenednew

comment:6 by Jacob, 17 years ago

Owner: changed from malcolm to Malcolm Tredinnick

comment:7 by Michael Radziej, 17 years ago

Cc: mir@… added

comment:8 by Malcolm Tredinnick, 17 years ago

Keywords: qs-rf removed
Resolution: fixed
Status: newclosed

Closing, since the original issue has been fixed and the fact that it will work when something like #5020 is dealt with is covered in #5020. The idea is to reduce the number of open tickets, folks, not keep lots of similar ones open.

Note: See TracTickets for help on using tickets.
Back to Top