On Wed, 2007-10-31 at 23:05 -0400, George Vilches wrote:
> Malcolm Tredinnick wrote:
> >>
> >>  >>> Assembly.objects.select_related()
> >> [<Assembly: Assembly object>, <Assembly: Assembly object>, <Assembly: 
> >> Assembly object>, <Assembly: Assembly object>, <Assembly: Assembly 
> >> object>, <Assembly: Assembly object>]
> >>  >>> len(Assembly.objects.select_related())
> >> 6
> >>  >>> Assembly.objects.select_related().count()
> >> 2L
> >>
> >>
> >> Since I'm using select_related(), I would expect it to follow the INNER 
> >> JOINs to do the .count().  I can force it to use the JOINs by doing this:
> > 
> > This is where you've made a mistake (aside from the to_field problem
> > Karen pointed out). Your assumption is wrong. select_related() is only
> > an optimisation as far as loading the data form the database. It should
> > *never* change the result of a quantitative query like this. If it does,
> > it would be a bug.
> > 
> > Regards,
> > Malcolm
> 
> 
> 
> So is it expected behavior then that when I use filter criteria like this:
> 
>  >>> 
> Assembly.objects.select_related().filter(item_group__id__gte=-1).count()
> 6L

Once again, the select_related() bit has nothing to do with it. The
filter() call is dragging in the remote table. Filters have an effect on
the result set, select_related() is just an optimisation that controls
when the result set pieces are retrieved.

Rather than addressing each of your questions one-by-one, since they're
all of the same variety, I'll simply repeat that if including
select_related() changes the result set, it's a bug. So you should try
each of your queries with and without select_related() if you're in
doubt.

Regards,
Malcolm

-- 
He who laughs last thinks slowest. 
http://www.pointy-stick.com/blog/


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