On Sat, Sep 12, 2009 at 8:55 PM, Daniel Roseman <dan...@roseman.org.uk>wrote:
> > On Sep 12, 9:53 pm, tom <toab...@googlemail.com> wrote: > > Hi, > > > > i want to produce a left-join query with the django orm. Can anybody > > help howto do the following query? > > > > SELECT S.value, D.value from data as S left join data as D on > > S.entry_id=D.entry_id; > > > > Cheers tom > > What's the point of this query? What are you trying to achieve? > > I believe Django will automatically do a left-join query if your > ForeignKey has null=False. But your question doesn't seem to be about > left join queries in general, it's about the specific case where you > join a table to itself. But without understanding why you'd want to do > what you're doing here, I can't answer. I believe the general reason for performing a query like this is to minimize the number of queries that have to be performed. What I think you want is select_related(). The docs don't mention ManyToMany fields but for ForeignKey fields it looks like it does what you are looking for. It's documented here: http://docs.djangoproject.com/en/dev/ref/models/querysets/#id4 --~--~---------~--~----~------------~-------~--~----~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---