On Mon, Feb 23, 2009 at 3:49 PM, Torsten Bronger <
bron...@physik.rwth-aachen.de> wrote:

>
> Hallöchen!
>
> Alex Gaynor writes:
>
> > On Mon, Feb 23, 2009 at 12:40 PM, sphogan <spho...@gmail.com> wrote:
> >
> >> [...]
> >>
> >> However, select_related() only works on the object the foreign
> >> key is declared on
> >> (http://docs.djangoproject.com/en/dev/ref/models/querysets/ #id4
> >> <http://docs.djangoproject.com/en/dev/ref/models/querysets/%0A#id4>;
> >> specifically, "You can only refer to ForeignKey relations in the
> >> list of fields passed to select_related.")  Presumably this is
> >> because it does an INNER JOIN rather than a LEFT OUTER JOIN and
> >> would therefore miss articles with no comments.
> >>
> >> What I would like to be able to do is:
> >>
> >> Article.objects.select_related('comment_set').all()
> >>
> >> This seems like a somewhat simple case and there seems to be no
> >> mention of it in the documentation anywhere.
> >
> > That's not possible,
>
> By principle, or just because Django can't do it (yet)?  The related
> feature request can be found at
> <http://code.djangoproject.com/ticket/2238>.  It it, I refer to
>
> http://rubynugs.blogspot.com/2008/07/couple-of-stupid-things-about-djano.html
> where a Rails fan claims that Rails can do it.
>
> I don't know much about SQL so I really would like to know whether
> this could be realised.
>
> Tschö,
> Torsten.
>
> --
> Torsten Bronger, aquisgrana, europa vetus
>                   Jabber ID: torsten.bron...@jabber.rwth-aachen.de
>
>
> >
>
I have no idea if it's possible, by my inclination is that it isn't since no
one seems to have ponied up the SQL to make it happen :) .  Further SQL
generally returns a list of tuples of scalars(to use there python datatypes)
SQL doesn't really ever return a collection, so my inclination is that it
can't.  Someone better versed in SQL can probably say for sure.  Regardless
it's still easy to get the data:

p =Post.object.get(pk=2)
p.comment_set.all() # all the comments for that post.

Alex
-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

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

Reply via email to