On Jul 29, 8:49 pm, thusjanthan <thusjant...@gmail.com> wrote: > Hi, > > I have the following relation: > > class Email(models.Model): > id = models.CharField(max_length=15,primary_key=True) > > ... > > class Person(models.Model): > id= models.CharField(max_length=15,primary_key=True) > email = models.ForeignKey(Email, db_column='id') > > When I do: Person.objects.select_related().all() > The query that is run is: > > SELECT id,email FROM Person INNER JOIN Email ON (Person.id = > Email.id) > > As you can see if a person did not have an email address, this will > produce an empty list. Is there any way to force select_related to do > a LEFT JOIN so that even if email is null, the person is returned with > email set to null. > > Cheers, > Thusjanthan.
It's not possible for a Person to exist without an Email in that model structure, as the foreignkey does not have null=True. So an inner join is the correct relationship. If you have null=True, it will correctly create a left outer join (although you do have to explicitly specify 'email' inside the select_related call, as it doesn't follow null=True relationships by default). -- DR. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.