I have taken a bit of time to rewrite part of the QuerySet code
(including select_related). Please, no lectures about a QuerySet
refactoring.
The changes force .filter() to take advantage of select_related.
Before: .filter(mykey__name='Hello') would give you results, but if
you didn't do .select_related(depth=1) you would not have mykey in
memory.
After: it does :P
The changes also change select_related's args:
MyModel.objects.filter(mykey__name="hello").select_related('mykey__author')
will automatically join on mykey__author and keep it in memory.
The biggest thing this fixes is the SQL query optimization, previously
it would have done two JOINs on mykey's table, even if the SQL engine
optimized it, it's best to optimize it in the code.
This also letse you say
MyModel.objects.all().select_related('mykey__author') which will hold
both mykey, and mykey__author values in memory on the objects.
The depth argument still exists, so
MyModel.objects.all().select_related('mykey', depth=1). The result of
this query.. is nothing, because you implicitly set the fields to
"mykey". If however, you said select_related('mykey__author', depth=1)
it would not select on author, only on mykey, because that was
specified.
If people are willing to discuss, or accept this, I will patch SVN
with it. I will still most likely release the patch as I know a LOT of
people want the "fields" selector in select_related().
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---