Re: OneToOneField direction? (was Re: QuerySet.count() inaccurate across ForeignKey relationships)

2007-11-01 Thread George Vilches
Karen Tracey wrote: > On 11/1/07, *George Vilches* <[EMAIL PROTECTED] > > wrote: > [snip] > > For reporting purposes though, we would like to be able to > .select_related() on User, and get a cached copy of each of the OneToOne > relationships. It seems rea

Re: OneToOneField direction? (was Re: QuerySet.count() inaccurate across ForeignKey relationships)

2007-11-01 Thread Karen Tracey
On 11/1/07, George Vilches <[EMAIL PROTECTED]> wrote: [snip] > For reporting purposes though, we would like to be able to > .select_related() on User, and get a cached copy of each of the OneToOne > relationships. It seems reasonable by the very essence of OneToOne, but > I don't know if there's

Re: OneToOneField direction? (was Re: QuerySet.count() inaccurate across ForeignKey relationships)

2007-11-01 Thread Malcolm Tredinnick
On Thu, 2007-11-01 at 08:53 -0400, George Vilches wrote: > (Off-list because this mostly doesn't apply to non qs-rf people) > > Thank you for the clarification on OneToOneFields and required > relationships. We've been working with a very high volume legacy > database that we're importing the

Re: OneToOneField direction? (was Re: QuerySet.count() inaccurate across ForeignKey relationships)

2007-11-01 Thread George Vilches
Alright, I guess it's not offlist. Sorry for the extra chatter folks. George Vilches wrote: > (Off-list because this mostly doesn't apply to non qs-rf people) > > Thank you for the clarification on OneToOneFields and required > relationships. We've been working with a very high volume legacy

OneToOneField direction? (was Re: QuerySet.count() inaccurate across ForeignKey relationships)

2007-11-01 Thread George Vilches
(Off-list because this mostly doesn't apply to non qs-rf people) Thank you for the clarification on OneToOneFields and required relationships. We've been working with a very high volume legacy database that we're importing the data into, and that data's not exactly pristine. We're used to re

Re: QuerySet.count() inaccurate across ForeignKey relationships

2007-10-31 Thread Malcolm Tredinnick
On Thu, 2007-11-01 at 15:55 +1100, Malcolm Tredinnick wrote: [...] > Unfortunately, SQLite and MySQL with the MyIsam > storage engine won't raise complaints (since they don't enforce the > integrity) and MySQL with the InnoDB engine has what is really a bug in > that you can't use normal SQL synt

Re: QuerySet.count() inaccurate across ForeignKey relationships

2007-10-31 Thread Malcolm Tredinnick
On Thu, 2007-11-01 at 00:43 -0400, George Vilches wrote: > Karen Tracey wrote: > > On 10/31/07, *George Vilches* <[EMAIL PROTECTED] > > > wrote: > > > > Or (I just saw your follow-up e-mail), is all of this a moot point since > > something like this is going to

Re: QuerySet.count() inaccurate across ForeignKey relationships

2007-10-31 Thread George Vilches
Karen Tracey wrote: > On 10/31/07, *George Vilches* <[EMAIL PROTECTED] > > wrote: > > 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? > > > That's it. Targeting

Re: QuerySet.count() inaccurate across ForeignKey relationships

2007-10-31 Thread Karen Tracey
On 10/31/07, George Vilches <[EMAIL PROTECTED]> wrote: > 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? > That's it. Targeting a non-unique column in a ForeignKey field is invalid. It's invalid now

Re: QuerySet.count() inaccurate across ForeignKey relationships

2007-10-31 Thread Malcolm Tredinnick
On Wed, 2007-10-31 at 23:05 -0400, George Vilches wrote: > Malcolm Tredinnick wrote: > >> > >> >>> Assembly.objects.select_related() > >> [, , >> Assembly object>, , >> object>, ] > >> >>> len(Assembly.objects.select_related()) > >> 6 > >> >>> Assembly.objects.select_related().count() > >> 2L

Re: QuerySet.count() inaccurate across ForeignKey relationships

2007-10-31 Thread George Vilches
Malcolm Tredinnick wrote: >> >> >>> Assembly.objects.select_related() >> [, , > Assembly object>, , > 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 I

Re: QuerySet.count() inaccurate across ForeignKey relationships

2007-10-31 Thread Malcolm Tredinnick
On Wed, 2007-10-31 at 18:45 -0400, George Vilches wrote: > First of all, thank you for the well thought-out response, I appreciate > your efforts. :) > > Here is the crux of the matter, without any examples, and you phrased it > best: > > "You've overridden that by > > specifying a to_field w

Re: QuerySet.count() inaccurate across ForeignKey relationships

2007-10-31 Thread Malcolm Tredinnick
On Wed, 2007-10-31 at 11:09 -0400, George Vilches wrote: > Stated simply: > queryset.select_related().count() with no filter criteria generates a > wrong query across a ForeignKey relationship. > > The problem: A QuerySet operation that involves a .count() across a > ForeignKey relationship doe

Re: QuerySet.count() inaccurate across ForeignKey relationships

2007-10-31 Thread George Vilches
First of all, thank you for the well thought-out response, I appreciate your efforts. :) Here is the crux of the matter, without any examples, and you phrased it best: > "You've overridden that by > specifying a to_field whose value is not unique (allowing that may be > a bug in Django)." T

Re: QuerySet.count() inaccurate across ForeignKey relationships

2007-10-31 Thread Karen Tracey
On 10/31/07, George Vilches <[EMAIL PROTECTED]> wrote: [snip] Here is what I want to count: > > "All the quantity of items necessary to complete all the selected > assemblies". > > That's not thinking in SQL, that's very much thinking about the objects > at hand. I have Assemblies, and I need to

Re: QuerySet.count() inaccurate across ForeignKey relationships

2007-10-31 Thread guettli . google
> But all of this is besides the point, because one way or the other, > Django is doing *something* wrong. Sometimes the .count() returns 6, > and sometimes it returns 2 in the provided examples. About .distinct(): Django does not count: It uses 'SELECT count(*) ...'. The results you see are

Re: QuerySet.count() inaccurate across ForeignKey relationships

2007-10-31 Thread George Vilches
koenb wrote: > First things first: I would either define a separate Group object > here, or use a many2manyfield if you don't need to know the group > numbers. The example was crafted because the actual models and data are part of a internal application that I am not allowed to publish the sourc

Re: QuerySet.count() inaccurate across ForeignKey relationships

2007-10-31 Thread koenb
First things first: I would either define a separate Group object here, or use a many2manyfield if you don't need to know the group numbers. Second thing: why use the assembly object if you want to count items ? You are thinking to much in SQL instead of ORM. If you say Assembly.objects.count(),

Re: QuerySet.count() inaccurate across ForeignKey relationships

2007-10-31 Thread George Vilches
[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

Re: QuerySet.count() inaccurate across ForeignKey relationships

2007-10-31 Thread guettli . google
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 def

QuerySet.count() inaccurate across ForeignKey relationships

2007-10-31 Thread George Vilches
Stated simply: queryset.select_related().count() with no filter criteria generates a wrong query across a ForeignKey relationship. The problem: A QuerySet operation that involves a .count() across a ForeignKey relationship does not actually join in the ForeignKey tables to do the select_relate