I'm diving into the sql that is being generated by django and am
having trouble understanding something.  Could someone give me a
hand?  Say I have a Book class like this:

class Book(models.Model):
   readers = models.ManyToMany('auth.user', blank=True, null=True)

Let's say for a given book object I do this:
   readers = book.readers.count()

When I look at the sql via db.connection.queries, I see this:

  SELECT COUNT(*) FROM auth_user INNER JOIN myapp_book_readers ON
(auth_user.id = myapp_book_readers.user_id) WHERE
myapp_book_readers.book_id` = 15

Why does the sql need to do an INNER JOIN with the auth_user table?
Why isn't the query simly this?

  SELECT COUNT(*) FROM book_readers WHERE book_readers.book_id = 15

Any pointers appreciated, thanks!

Margie

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to