<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Custom JOINs with Django&#8217;s query.join()</title>
	<atom:link href="http://www.caktusgroup.com/blog/2009/09/28/custom-joins-with-djangos-queryjoin/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.caktusgroup.com/blog/2009/09/28/custom-joins-with-djangos-queryjoin/</link>
	<description>Blog &#124; Django Web Development &#124; Raleigh Durham Chapel Hill &#124; Caktus Consulting Group</description>
	<pubDate>Thu, 09 Sep 2010 15:50:26 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
		<item>
		<title>By: theY4Kman</title>
		<link>http://www.caktusgroup.com/blog/2009/09/28/custom-joins-with-djangos-queryjoin/#comment-521</link>
		<dc:creator>theY4Kman</dc:creator>
		<pubDate>Sat, 20 Feb 2010 05:41:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.caktusgroup.com/blog/?p=338#comment-521</guid>
		<description>Thank you so much! This article has helped me a lot!

I needed to use multiple LEFT JOINs on the same table, and I was pulling my hair out until I looked at query.join. It returns an alias that points to that particular join.

alias1 = contacts.query.join(...)
alias2 = contacts.query.join(...)
contacts = contacts.extra(where=[alias1+'.id=1', alias2+'.id=3'])</description>
		<content:encoded><![CDATA[<p>Thank you so much! This article has helped me a lot!</p>
<p>I needed to use multiple LEFT JOINs on the same table, and I was pulling my hair out until I looked at query.join. It returns an alias that points to that particular join.</p>
<p>alias1 = contacts.query.join(&#8230;)<br />
alias2 = contacts.query.join(&#8230;)<br />
contacts = contacts.extra(where=[alias1+'.id=1', alias2+'.id=3'])</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vinilios</title>
		<link>http://www.caktusgroup.com/blog/2009/09/28/custom-joins-with-djangos-queryjoin/#comment-419</link>
		<dc:creator>Vinilios</dc:creator>
		<pubDate>Wed, 07 Oct 2009 21:06:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.caktusgroup.com/blog/?p=338#comment-419</guid>
		<description>Very interesting article, its amazing that you posted this while i was trying to solve same issues in a i18n application i'm currently developing, and this is really useful joining translation objects with their translations within a single query.

What would be super cool would be a way to keep 'join compatibility' within the queryset so something like the following will work within the custom joins (after a quick test it seems that queryset defines an additional join for which the filter conditions are set):

contacts.query.join(connection, promote=True).filter(phones__phone__startswith=.....)</description>
		<content:encoded><![CDATA[<p>Very interesting article, its amazing that you posted this while i was trying to solve same issues in a i18n application i&#8217;m currently developing, and this is really useful joining translation objects with their translations within a single query.</p>
<p>What would be super cool would be a way to keep &#8216;join compatibility&#8217; within the queryset so something like the following will work within the custom joins (after a quick test it seems that queryset defines an additional join for which the filter conditions are set):</p>
<p>contacts.query.join(connection, promote=True).filter(phones__phone__startswith=&#8230;..)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: copelco</title>
		<link>http://www.caktusgroup.com/blog/2009/09/28/custom-joins-with-djangos-queryjoin/#comment-408</link>
		<dc:creator>copelco</dc:creator>
		<pubDate>Wed, 30 Sep 2009 14:50:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.caktusgroup.com/blog/?p=338#comment-408</guid>
		<description>Good point, a &lt;a href='http://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-on-many-to-many-relationships' rel="nofollow"&gt;"through"&lt;/a&gt; model will work nicely in this scenario, though joining through multiple M2M relationships might not work.  Another issue we have run across in the past involves using qs.extra() to call a SQL function on a related table that Django is unaware of.  select_related() will not work and filter() (which will construct the JOINs) doesn't support SQL functions.  You really want to use the ORM to construct the join and just tap in at the end with qs.extra() to add some custom SQL.</description>
		<content:encoded><![CDATA[<p>Good point, a <a href='http://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-on-many-to-many-relationships' rel="nofollow">&#8220;through&#8221;</a> model will work nicely in this scenario, though joining through multiple M2M relationships might not work.  Another issue we have run across in the past involves using qs.extra() to call a SQL function on a related table that Django is unaware of.  select_related() will not work and filter() (which will construct the JOINs) doesn&#8217;t support SQL functions.  You really want to use the ORM to construct the join and just tap in at the end with qs.extra() to add some custom SQL.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Yishai</title>
		<link>http://www.caktusgroup.com/blog/2009/09/28/custom-joins-with-djangos-queryjoin/#comment-407</link>
		<dc:creator>Yishai</dc:creator>
		<pubDate>Wed, 30 Sep 2009 10:43:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.caktusgroup.com/blog/?p=338#comment-407</guid>
		<description>What worked for me and seemed nicer in terms of the code is use a "through" model instead of the regular M2M relation. You still get all the benefits of the M2M relation, but you can now query directly on the through model to get your cartesian product.</description>
		<content:encoded><![CDATA[<p>What worked for me and seemed nicer in terms of the code is use a &#8220;through&#8221; model instead of the regular M2M relation. You still get all the benefits of the M2M relation, but you can now query directly on the through model to get your cartesian product.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tobias</title>
		<link>http://www.caktusgroup.com/blog/2009/09/28/custom-joins-with-djangos-queryjoin/#comment-404</link>
		<dc:creator>tobias</dc:creator>
		<pubDate>Tue, 29 Sep 2009 22:59:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.caktusgroup.com/blog/?p=338#comment-404</guid>
		<description>You'll have to fall back to raw SQL for this one.  Check out &lt;a href='http://code.djangoproject.com/ticket/11863' rel="nofollow"&gt;ticket #11863&lt;/a&gt; for upcoming changes that might help with this.</description>
		<content:encoded><![CDATA[<p>You&#8217;ll have to fall back to raw SQL for this one.  Check out <a href='http://code.djangoproject.com/ticket/11863' rel="nofollow">ticket #11863</a> for upcoming changes that might help with this.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jay</title>
		<link>http://www.caktusgroup.com/blog/2009/09/28/custom-joins-with-djangos-queryjoin/#comment-398</link>
		<dc:creator>Jay</dc:creator>
		<pubDate>Tue, 29 Sep 2009 02:47:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.caktusgroup.com/blog/?p=338#comment-398</guid>
		<description>Currently I use custom SQL to do complex joins. This post gives me a new choice. But what if I want to do RIGHT OUTER JOIN or FULL OUTER JOIN? Is there a method in Django's ORM?</description>
		<content:encoded><![CDATA[<p>Currently I use custom SQL to do complex joins. This post gives me a new choice. But what if I want to do RIGHT OUTER JOIN or FULL OUTER JOIN? Is there a method in Django&#8217;s ORM?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Claude</title>
		<link>http://www.caktusgroup.com/blog/2009/09/28/custom-joins-with-djangos-queryjoin/#comment-395</link>
		<dc:creator>Claude</dc:creator>
		<pubDate>Mon, 28 Sep 2009 20:01:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.caktusgroup.com/blog/?p=338#comment-395</guid>
		<description>Well, very interesting! This is a common performance problem in Django apps.
I has been confronted to such a situation in one of my apps, where I choose to join the results of two separate queries in Python code. That was not nice at all, but at least prevented many hundreds of database queries...</description>
		<content:encoded><![CDATA[<p>Well, very interesting! This is a common performance problem in Django apps.<br />
I has been confronted to such a situation in one of my apps, where I choose to join the results of two separate queries in Python code. That was not nice at all, but at least prevented many hundreds of database queries&#8230;</p>
]]></content:encoded>
	</item>
</channel>
</rss>
