On Sun, Mar 21, 2010 at 8:17 AM, Henrik Genssen
<[email protected]> wrote:
> No one any comment on this?
> is this the expected behavior?
...
>>Now is there a way to force select_related tables any way in a count?

select_related() is an optimization for data retrieval. It allows you
to expand a select row to include related objects in a single query.

It only follows the "1" side of "1-N" relations. That is, if a book
has a foreign key on author, Book has a single Author. If you request
N books, you will need to issue N+1 SQL queries. With select_related,
this becomes 1 SQL query, and each row in the result set includes the
details of the book and the details of the single related author.

This *does not* affect the row count. The number of books doesn't
change as a result of including related authors in the result set.
Hence, select_related() clauses are removed prior to a call to
count().

select_related() is *not* a way to force a table join. If you need a
table join, you need to add a filter() that traverses the join.
Alternatively, you could expand your extra() clause to force the extra
join condition.

Yours,
Russ Magee %-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" 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-users?hl=en.

Reply via email to