select_related() filters objects with ANY fk foreign relation
|Reported by:||Doug Napoleone||Owned by:||adrian|
|Component:||Database layer (models, ORM)||Version:||master|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
This is different from not following FK relations with null=True which is documented.
This is select_related() EXCLUDING relations with any fk null=True where ANY fk row entry is Null.
[<ScheduledEvent: ScheduledEvent object>]
ScheduledEvents have other FK's besides 'room' which are not 'null=True', for which select_related() gives a good speedup (5x over 8000 rows w/ 4 FK's). Unfortunatly it excludes all relations with a null room FK.
My current workaround is to create a special 'NULL' room which now needs to be queried for, the id cached, and .exclude(room=NullRoomId) added as a special object manager on the class. Less than optimal and would hate to have to do with for all my null=True fk relations, but might help others with this problem.