[EMAIL PROTECTED] wrote:
> On Wed, Oct 31, 2007 at 11:09:49AM -0400, George Vilches wrote:
>> Stated simply:
>> queryset.select_related().count() with no filter criteria generates a 
>> wrong query across a ForeignKey relationship.
> 
> Hi,
> 
> do you get the correct results, if you use .distinct()?
> 
> Distinct is not enabled by default. This means, a query over foreignkeys
> can give you duplicate entries in the queryset.
> 
>  Thomas
> 

I do not get the correct results if I use .distinct(), and that's to be 
expected, because the INNER JOIN results are 6 totally unique rows.  For 
verification:

 >>> Assembly.objects.select_related().distinct().count()
2L

But the results actually expand to show things that are even more 
...wrong/strange/odd:


 >>> 
Assembly.objects.select_related().filter(item_group__id__gte=-1).distinct() 

[<Assembly: Assembly object>, <Assembly: Assembly object>, <Assembly: 
Assembly object>, <Assembly: Assembly object>, <Assembly: Assembly 
object>, <Assembly: Assembly object>]
 >>> 
Assembly.objects.select_related().filter(item_group__id__gte=-1).distinct().count()
2L
 >>> 
Assembly.objects.select_related().filter(item_group__id__gte=-1).count()
6L


Why would the .distinct() show 6 objects, but the .distinct().count() 
only show a count of 2?  Something seems broken about this.


Thanks,
George

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to