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 That I get 6 instead of 2? (It appears that the combination of select_related() and filter() is now affecting the count of the Assembly rows in the query, which is what would be expected from a strictly SQL perspective). If that's correct, then is this also correct? (rehash of the message about distinct()/count()): >>> 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 Or (I just saw your follow-up e-mail), is all of this a moot point since something like this is going to be made totally invalid in the future? 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 -~----------~----~----~----~------~----~------~--~---