Brilliant, I feel slightly less of a fool now. :)

On 23 Jun 2008, at 15:05, George Vilches wrote:

>
> You'll be happy to know that there's a ticket in the system that
> already resolves this problem: http://code.djangoproject.com/ticket/
> 7512 .  It will properly LEFT JOIN whenever ordering occurs on
> null=True relationships on any of the major field types.
>
> gav
>
> On Jun 23, 2008, at 10:00 AM, Mike H wrote:
>
>>
>>
>> Gah... ignore! Even though the foreignkey was nullable, I had an
>> ordering entry in the Meta class which ordered by deployment__name
>> which forced the inner join.
>>
>> I'll be quiet now... ;-)
>>
>> Mike
>>
>> On 23 Jun 2008, at 14:51, Mike H wrote:
>>
>>>
>>> Hi all,
>>>
>>> Before I rush off and possibly file a bogus bug report, am I seeing
>>> incorrect behavior here?
>>>
>>> I have a simple 'Project' model, as so:
>>>
>>> class Project(models.Model):
>>>   deployment = models.ForeignKey(Deployment, blank=True, null=True)
>>>   ... some other fields here
>>>
>>> Some of the projects in the db do not have a deployment.
>>>
>>> When I run
>>>
>>> Project.objects.all().count() it counts all the records in the
>>> project
>>> table.
>>>
>>> When I run
>>>
>>> Project.objects.all() it tries to do an inner join to the deployment
>>> table, which of course cuts out all projects that don't have a
>>> deployment.
>>>
>>>>>> m.Project.objects.all().query.as_sql()
>>> ('SELECT `tasks_project`.`id`, `tasks_project`.`deployment_id`,
>>> `tasks_project`.`name`, `tasks_project`.`active`,
>>> `tasks_project`.`is_support` FROM `tasks_project` INNER JOIN
>>> `tasks_deployment` ON (`tasks_project`.`deployment_id` =
>>> `tasks_deployment`.`id`) ORDER BY `tasks_deployment`.`name` ASC,
>>> `tasks_project`.`name` ASC', ())
>>>
>>> I have tried .select_related(depth=0) but that returns exactly the
>>> same sql, which really, to my mind anyway, it should not. I
>>> explicitly
>>> asked it not to select the deployments with depth=0, didn't I?
>>>
>>> I am running revision 7569 of trunk.
>>>
>>> Cheers,
>>>
>>> Mike
>>>
>>>>
>>
>>
>>>
>
>
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to