On 29 heinä, 22:49, 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.

You have set the email field (implicitly) as null=False, that is,
every person must have an associated email, hence left join will not
make sense in this query.

However, your example shows a validation bug: setting the
db_column='id' and having a column named id should clearly be an
error. I have opened a ticket for this (#14028).

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

Reply via email to