Re: select_related() and reverse foreign keys -OR- how to I get a blog post and its comments?

2009-02-24 Thread Malcolm Tredinnick
On Tue, 2009-02-24 at 11:34 -0500, Sean Patrick Hogan wrote: > Thanks for the input! So, I'm assuming by "easiest case" you mean > just calling LEFT OUTER JOINs. That's Rails behavior and then it > deals with it in Ruby. I'm not too familiar with SQLAlchemy, but it > looks like that's what they

Re: select_related() and reverse foreign keys -OR- how to I get a blog post and its comments?

2009-02-24 Thread Sean Patrick Hogan
Thanks for the input! So, I'm assuming by "easiest case" you mean just calling LEFT OUTER JOINs. That's Rails behavior and then it deals with it in Ruby. I'm not too familiar with SQLAlchemy, but it looks like that's what they're doing in their EagerLoader as well. The only way I can think of o

Re: select_related() and reverse foreign keys -OR- how to I get a blog post and its comments?

2009-02-23 Thread Malcolm Tredinnick
On Mon, 2009-02-23 at 21:49 +0100, Torsten Bronger wrote: > Hallöchen! > > Alex Gaynor writes: > > > On Mon, Feb 23, 2009 at 12:40 PM, sphogan wrote: [...] > >> What I would like to be able to do is: > >> > >> Article.objects.select_related('comment_set').all() > >> > >> This seems like a some

Re: select_related() and reverse foreign keys -OR- how to I get a blog post and its comments?

2009-02-23 Thread Karen Tracey
On Mon, Feb 23, 2009 at 12:40 PM, sphogan wrote: > > I'm surprised that this hadn't come up for me before, but nonetheless, > here I am. > > My problem is that I want to get related items (in a similar situation > to getting blog articles with their comments) without looping a second > lookup (si

Re: select_related() and reverse foreign keys -OR- how to I get a blog post and its comments?

2009-02-23 Thread Alex Gaynor
On Mon, Feb 23, 2009 at 4:10 PM, Sean Patrick Hogan wrote: > It isn't *an* extra SQL query that I'm worried about. It's that it's going > to be about 2,000 extra SQL queries in a loop. If it were just constructing > a page with one item and then its related items, that's not a problem to do > tw

Re: select_related() and reverse foreign keys -OR- how to I get a blog post and its comments?

2009-02-23 Thread Sean Patrick Hogan
It isn't *an* extra SQL query that I'm worried about. It's that it's going to be about 2,000 extra SQL queries in a loop. If it were just constructing a page with one item and then its related items, that's not a problem to do two queries, but when you're looping over 2,000 items and running an

Re: select_related() and reverse foreign keys -OR- how to I get a blog post and its comments?

2009-02-23 Thread Alex Gaynor
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 wrote: > > > >> [...] > >> > >> However, select_related() only works on the object the foreign > >> key is declared on >

Re: select_related() and reverse foreign keys -OR- how to I get a blog post and its comments?

2009-02-23 Thread Torsten Bronger
Hallöchen! Alex Gaynor writes: > On Mon, Feb 23, 2009 at 12:40 PM, sphogan 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 >>

Re: select_related() and reverse foreign keys -OR- how to I get a blog post and its comments?

2009-02-23 Thread Alex Gaynor
On Mon, Feb 23, 2009 at 12:40 PM, sphogan wrote: > > I'm surprised that this hadn't come up for me before, but nonetheless, > here I am. > > My problem is that I want to get related items (in a similar situation > to getting blog articles with their comments) without looping a second > lookup (si

select_related() and reverse foreign keys -OR- how to I get a blog post and its comments?

2009-02-23 Thread sphogan
I'm surprised that this hadn't come up for me before, but nonetheless, here I am. My problem is that I want to get related items (in a similar situation to getting blog articles with their comments) without looping a second lookup (since it would be a couple thousand items and building a page off