Hi,
I have three models, listed at [1], that I want to get data from with
only one query, because of performance issues with my app. The way
that worked so far is:

league_ids = [12, 21]
bets = 
models.Bet.objects.filter(game__league__id__in=league_ids).order_by('bet__game__league.id',
'game_part', 'bet__game.venuedate')

The problem with this is that for each bet I iterate, the database
will be hit one or more times because I need to use
bet.game.league.name and so on. So I tried adding .select_related() to
the query and now it returns no results, while without
select_related() I get 172 results. Looking at the sql generated by
the query with and without select_related() I noticed that with it,
the sql was very strange, when the orm could have just added fields
from the other tables to the select list. Please look at the original
generated sql at [2] and the one with select_related() at [3]. This
looks like a bug to me, at least on the documentation, if I am not
supposed to use select_related() with queries like this.

BTW, is there are any better way to do what I want (get columns from
the three models in only one query) with the django orm? I tried to
use .values() in the query but it turns out that I cannot specify
columns from other tables in it. For now I'll be using the sqlalchemy
model I already have for this database, but I'd really appreciate to
do everything with the django parts, since they seem to fit very good
together and this is the first really bad problem I found while
developing with django.


[1] http://dpaste.com/8743/
[2] http://dpaste.com/8581/
[3] http://dpaste.com/8582/

-- 
[]'s,
Luiz Carlos Geron

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