On Mon, 2007-06-04 at 10:11 +0200, Horst Gutmann wrote:
> Hi everyone :-)
> 
> I'm currently writing a small app that should store data for registered
> users and guests alike in one single model. So I made following model
> (simplied)
> 
>    class Content(models.Model):
>       user = models.ForeignKey(User, null=True, blank=True)
> 
> The problem I now face is, that Django seems not to do a LEFT OUTER JOIN
> when fetching all the instances of this model when queried with
> select_related(), which naturally results in a huge amount of queries (I
> guess on query per NOT NULL foreign key).

This is ongoing work as part of the Queryset refactor. It's hard to fix
in a general way with the current code, but easy in the redesign. So the
"true" answer to your question is "wait a little while".

> 
> My question now is, what options do I have to keep the query count low?
> So far I think I have following ones:
> 
> (1) Query without selected related and then fill the content.user fields
> manually with a seperate WHERE IN query for the user.ids
> 
> (2) Use something like Martin Fowler's NULL Object pattern and basically
> create a user with the ID 0 (or a negative integer if possible)

If all guests can be treated as the same object, that is a good solution
at the moment. I've used it before with success; although I managed to
avoid using any buzzwords like "Martin Fowler" or "pattern" -- you just
make a user called "AnonymousFred" and do stuff with that.

Regards,
Malcolm


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