Opened 16 years ago

Last modified 15 years ago

#11199 closed

Select_related added to the query set will produce empty result — at Version 1

Reported by: milosu Owned by: nobody
Component: Database layer (models, ORM) Version: 1.0
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Alex Gaynor)

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)..

Change History (1)

comment:1 by Alex Gaynor, 16 years ago

Description: modified (diff)

Please use preview.

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