select_related does not work with nullable fields unless field is specified.
|Reported by:||dloewenherz||Owned by:||nobody|
|Has patch:||no||Needs documentation:||yes|
|Needs tests:||no||Patch needs improvement:||no|
Say I have the following model:
class Book(models.Model): owner = models.ForeignKey(Owner, related_name='books')
Book.objects.select_related() will pull in all owner data. HOWEVER, when the owner field is nullable, no joins occur.
class Book(models.Model): owner = models.ForeignKey(Owner, null=True, blank=True, related_name='books')
Running a join in my database involving a nullable field works exactly as would one on a non-nullable field, so I can't really see a good reason for this to happen.
Change History (5)
comment:1 Changed 4 years ago by AndrewIngram
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
comment:3 Changed 4 years ago by aaugustin
- Triage Stage changed from Unreviewed to Design decision needed
comment:4 Changed 4 years ago by mtredinnick
- Component changed from Database layer (models, ORM) to Documentation
- Needs documentation set
- Summary changed from select_related does not work with nullable fields to select_related does not work with nullable fields unless field is specified.
- Triage Stage changed from Design decision needed to Accepted