On Aug 11, 9:44 am, Sam Walters <mr.sam...@gmail.com> wrote:
> I dont think they do.
>
> The only time i use raw sql + joins is for performance... eg:
>
> When you have a model and for each instance of that model it has a
> reverse foreignkey relationship where you would have to call:
> <related_model_name>_set.all()
> in a for loop thus making heaps of sql queries.
>
> There are 3rd party addons for 
> that:http://code.google.com/p/django-selectreverse/
> Does a good job of avoiding the n+1 problem for most situations.

If there are more than one related object in the related set, this is
better approach to fetching the related objects than joins. Even more
so if you are fetching multiple related sets. But if you are fetching
just one related object from the related set (for example translation
in finnish from the translations_set), then a join (or left join)
would be better. There is currently no way I know of to do left joins
with additional filters in the join clause. In my opinion this is one
of the two ORM features really needed. The other is composite primary
keys and foreign keys.

- Anssi

>
> Hope this helps
>
> cheers
>
> sam.
>
> On Wed, Aug 11, 2010 at 4:36 PM, Daniel Roseman <dan...@roseman.org.uk> wrote:
> > On Aug 11, 2:28 am, Phlip <phlip2...@gmail.com> wrote:
> >> >  orders = Order.objects.filter(
> >> >    pk=42,
> >> >    order_items__product='whiteboards'
> >> >    )
>
> >> > Is this not what you want?
>
> >> We made a feeb attempt at that and gave up. Thanks! I will try it next.
>
> >> The next question, if it works, will be how to values_list() a field
> >> from a child record; it might follow that notation.
>
> >> Could I trouble you for its home page? Googling for [django queryset
> >> join] gives zillions of newbs trying simple queries...
>
> >http://docs.djangoproject.com/en/1.2/topics/db/queries/#lookups-that-...
>
> > --
> > DR.
>
> > --
> > 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 
> > athttp://groups.google.com/group/django-users?hl=en.

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