Thanks Malcom. Will your rewrite make it possible to easily fetch
ForeignKey(null=True) and M2M sub-objects? That would solve my
(performance) problem.
JJ.
On Jul 17, 11:07 am, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Tue, 2007-07-17 at 01:59 -0700, jj wrote:
> > It's easy to fetch extra object attributes with extra(select={...}).
>
> > But how can I obtain extra sub-objects (easily, without resorting to
> > custom SQL)?
>
> > I'd like to be able to do something like the following, but obviously
> > this doesn't work:
> > extra(select={'country': 'SELECT book_country.name,
> > book_country.code'})
>
> > What works is:
> > extra(select={'country_name': 'SELECT book_country.name'},
> > 'country_code': 'SELECT book_country.code'})
>
> That's the way to do it (or custom SQL). At some point, if you're
> wanting to have tight control over the SQL like this, you should expect
> to write it directly. There's nothing bad about that. Django doesn't
> replace SQL for those who want that control.
>
> Even with the work I'm doing at the moment making query construction
> easier with the QuerySet rewrite, a lot of nested queries won't become
> too much easier, at least initially, since the nested query depends on
> values in the outer query (otherwise you could run it separately, or
> could de-nest it) and it's hard to make it easy to pass those
> dependencies around without reimplementing SQL, which, again, is not a
> very worthwhile exercise.
>
> Regards,
> Malcolm
>
> --
> The early bird may get the worm, but the second mouse gets the
> cheese.http://www.pointy-stick.com/blog/
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---