Select_related added to the query set will produce empty result
|Reported by:||milosu||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||1.0|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Description (last modified by Alex)
You have a model like:
class Driver: name = models.CharField(max_length=100) class Car: name = models.CharField(max_length=100) driver = models.ForeignKey(Driver)
Inside the database mangle the fkey from car to driver as nullable and insert some records into car table without the reference to the driver table.
Than just try:
Car.objects.filter(name = 'something').select_related()
and you will get empty queryset when evaluated.
I guess this is a correct ORM behaviour when using inner joins etc.
Could this be documented somewhere? It was quite mysterious for me to make an observation like this and to find the problem (missing null=True model declaration)..