On Sat, 2009-04-11 at 01:02 -0700, nikita kozlovsky wrote: > On Apr 11, 3:11 am, Malcolm Tredinnick <malc...@pointy-stick.com> > wrote: > > > > Django's SQL is going exactly what you suspect and not using any outer > > join here. Using a simplified version of the original two models: > > > > class Student(models.Model): > > ... > > > > class Message(models.Model): > > title = models.CharField(max_length=50) > > student = models.ForeignKey(Student) > > > > ... the SQL that is generated for Message.objects.filter(student=None) > > is: > > > > SELECT `outer_message`.`id`, `outer_message`.`title`, > > `outer_message`.`student_id` FROM `outer_message` WHERE > > `outer_message`.`student_id` IS NULL > > Yes, this correctly if student = models.ForeignKey(Student). > I use this simplified models with student = models.ForeignKey > (Student, null=True), sql that is generated for Message.objects.filter > (student=None) is: > > SELECT "messages_message"."id", "messages_message"."title", > "messages_message"."student_id" FROM "messages_message" LEFT OUTER > JOIN "messages_student" ON ("messages_message"."student_id" = > "messages_student"."id") WHERE "messages_student"."id" IS NULL
That's definitely a small bug, then. I've opened ticket #10790 so that it gets fixed eventually. Since it's not a functionality bug (the answer is still correct), it will be fixed after 1.1 now, but we will fix it. I understand why it's occurring (the comparison to NULL is a very special case in this situation). Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---