select_related does not work with nullable fields unless field is specified.
|Reported by:||Dan Loewenherz||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:4 Changed 5 years ago by
|Component:||Database layer (models, ORM) → Documentation|
|Summary:||select_related does not work with nullable fields → select_related does not work with nullable fields unless field is specified.|
|Triage Stage:||Design decision needed → Accepted|