<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: CakePHP Containable Statement Pitfalls</title>
	<atom:link href="http://www.endyourif.com/cakephp-containable-statement-pitfalls/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.endyourif.com/cakephp-containable-statement-pitfalls/</link>
	<description>Helping you solve those tough coding problems!</description>
	<lastBuildDate>Tue, 31 Aug 2010 08:55:25 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Adnan</title>
		<link>http://www.endyourif.com/cakephp-containable-statement-pitfalls/comment-page-1/#comment-936</link>
		<dc:creator>Adnan</dc:creator>
		<pubDate>Wed, 27 Jan 2010 14:22:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.endyourif.com/?p=227#comment-936</guid>
		<description>thanks a lot to @Abba Bryant. The code in the original post is not readable. I took the code from your comment and it worked great.</description>
		<content:encoded><![CDATA[<p><code>thanks a lot to @Abba Bryant. The code in the original post is not readable. I took the code from your comment and it worked great.</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mihai</title>
		<link>http://www.endyourif.com/cakephp-containable-statement-pitfalls/comment-page-1/#comment-923</link>
		<dc:creator>Mihai</dc:creator>
		<pubDate>Wed, 20 Jan 2010 09:06:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.endyourif.com/?p=227#comment-923</guid>
		<description>@saintberry You don&#039;t have to let your self in the hands of ORM. If you want to build reliable apps, you must know SQL as well.</description>
		<content:encoded><![CDATA[<p><code>@saintberry You don&#8217;t have to let your self in the hands of ORM. If you want to build reliable apps, you must know SQL as well.</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: flyff money</title>
		<link>http://www.endyourif.com/cakephp-containable-statement-pitfalls/comment-page-1/#comment-916</link>
		<dc:creator>flyff money</dc:creator>
		<pubDate>Fri, 15 Jan 2010 04:54:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.endyourif.com/?p=227#comment-916</guid>
		<description>nice post, thank you</description>
		<content:encoded><![CDATA[<p><code>nice post, thank you</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Axel</title>
		<link>http://www.endyourif.com/cakephp-containable-statement-pitfalls/comment-page-1/#comment-837</link>
		<dc:creator>Axel</dc:creator>
		<pubDate>Mon, 23 Nov 2009 23:27:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.endyourif.com/?p=227#comment-837</guid>
		<description>helped me a lot, thank you!</description>
		<content:encoded><![CDATA[<p><code>helped me a lot, thank you!</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Metin2 yang</title>
		<link>http://www.endyourif.com/cakephp-containable-statement-pitfalls/comment-page-1/#comment-795</link>
		<dc:creator>Metin2 yang</dc:creator>
		<pubDate>Thu, 12 Nov 2009 02:55:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.endyourif.com/?p=227#comment-795</guid>
		<description>I believe so. This seems to be the default setting on all of the projects that I have worked with, so I’ve only had to turn it down from 2.</description>
		<content:encoded><![CDATA[<p><code>I believe so. This seems to be the default setting on all of the projects that I have worked with, so I’ve only had to turn it down from 2.</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: OJ Tibi</title>
		<link>http://www.endyourif.com/cakephp-containable-statement-pitfalls/comment-page-1/#comment-791</link>
		<dc:creator>OJ Tibi</dc:creator>
		<pubDate>Tue, 03 Nov 2009 01:54:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.endyourif.com/?p=227#comment-791</guid>
		<description>Good point, although I still prefer to use Containable just because it paginates easier than that created from a flat query, well at least if I don&#039;t convert it into an associative array.</description>
		<content:encoded><![CDATA[<p><code>Good point, although I still prefer to use Containable just because it paginates easier than that created from a flat query, well at least if I don&#8217;t convert it into an associative array.</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: flyff gold</title>
		<link>http://www.endyourif.com/cakephp-containable-statement-pitfalls/comment-page-1/#comment-683</link>
		<dc:creator>flyff gold</dc:creator>
		<pubDate>Sat, 22 Aug 2009 03:02:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.endyourif.com/?p=227#comment-683</guid>
		<description>Good article - plenty of food for thought.</description>
		<content:encoded><![CDATA[<p><code>Good article &#8211; plenty of food for thought.</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: wow gold</title>
		<link>http://www.endyourif.com/cakephp-containable-statement-pitfalls/comment-page-1/#comment-634</link>
		<dc:creator>wow gold</dc:creator>
		<pubDate>Fri, 26 Jun 2009 01:12:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.endyourif.com/?p=227#comment-634</guid>
		<description>Good post,This was exactly what I needed to read today!  I am sure this has relevance to many of us out there.</description>
		<content:encoded><![CDATA[<p><code>Good post,This was exactly what I needed to read today!  I am sure this has relevance to many of us out there.</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jamie</title>
		<link>http://www.endyourif.com/cakephp-containable-statement-pitfalls/comment-page-1/#comment-61</link>
		<dc:creator>Jamie</dc:creator>
		<pubDate>Tue, 17 Mar 2009 23:43:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.endyourif.com/?p=227#comment-61</guid>
		<description>Thanks very much for the feedback guys.  I will definitely check out the linkable behavior.</description>
		<content:encoded><![CDATA[<p><code>Thanks very much for the feedback guys.  I will definitely check out the linkable behavior.</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: saintberry</title>
		<link>http://www.endyourif.com/cakephp-containable-statement-pitfalls/comment-page-1/#comment-60</link>
		<dc:creator>saintberry</dc:creator>
		<pubDate>Tue, 17 Mar 2009 23:28:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.endyourif.com/?p=227#comment-60</guid>
		<description>The Containable behaviour is a joke. Couldn&#039;t believe it when I found this out a few months ago. No idea why they include it in the core...

Personally I avoid writing custom SQL as much as possible. Being database agnostic is a huge advantage of any framework that implements a decent database abstraction layer (as Cake does), so I would only lose that as a very last resort (you ever had a requirement to switch from MySQL to PostgreSQL in production? I have, it&#039;s a pain!).

Luckily there is an alternative to both solutions outlined in this article. Rafael Bandeira has created the Linkable behaviour (http://rafaelbandeira3.wordpress.com/2008/11/16/linkable-behavior-taking-it-easy-in-your-db/) which basically replicates what the Containable behavior can do but using joins. The interface is much the same as Containable so usually it&#039;s a seamless drop in. There are a few limitations, but not many. Check it out.</description>
		<content:encoded><![CDATA[<p><code>The Containable behaviour is a joke. Couldn&#8217;t believe it when I found this out a few months ago. No idea why they include it in the core&#8230;</p><p>Personally I avoid writing custom SQL as much as possible. Being database agnostic is a huge advantage of any framework that implements a decent database abstraction layer (as Cake does), so I would only lose that as a very last resort (you ever had a requirement to switch from MySQL to PostgreSQL in production? I have, it&#8217;s a pain!).</p><p>Luckily there is an alternative to both solutions outlined in this article. Rafael Bandeira has created the Linkable behaviour (<a href="http://rafaelbandeira3.wordpress.com/2008/11/16/linkable-behavior-taking-it-easy-in-your-db/" rel="nofollow">http://rafaelbandeira3.wordpress.com/2008/11/16/linkable-behavior-taking-it-easy-in-your-db/</a>) which basically replicates what the Containable behavior can do but using joins. The interface is much the same as Containable so usually it&#8217;s a seamless drop in. There are a few limitations, but not many. Check it out.</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Abba Bryant</title>
		<link>http://www.endyourif.com/cakephp-containable-statement-pitfalls/comment-page-1/#comment-57</link>
		<dc:creator>Abba Bryant</dc:creator>
		<pubDate>Tue, 17 Mar 2009 03:00:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.endyourif.com/?p=227#comment-57</guid>
		<description>I just checked and for me at least setting both recursive and contains is not needed. It seems the containable behavior sets it for you.

also a more elegant method for the same results would be do to some ad-hoc joins on the model-&gt;find as per &lt;a href=&quot;http://bakery.cakephp.org/articles/view/quick-tip-doing-ad-hoc-joins-in-model-find&quot; rel=&quot;nofollow&quot;&gt;http://bakery.cakephp.org/articles/view/quick-tip-doing-ad-hoc-joins-in-model-find&lt;/a&gt;

&lt;code&gt;
$data = $this-&gt;User-&gt;find( &#039;all&#039;, array( &#039;joins&#039; =&gt; array(
	array(
		&#039;table&#039; 		=&gt; 	&#039;albums&#039;	,
		&#039;alias&#039;			=&gt;	&#039;Album&#039;		,
		&#039;type&#039;			=&gt;	&#039;inner&#039;		,
		&#039;foreignKey&#039;	=&gt;	&#039;user_id&#039;	,
	),
	array(
		&#039;table&#039; 		=&gt; 	&#039;photos&#039;	,
		&#039;alias&#039;			=&gt;	&#039;Photo&#039;		,
		&#039;type&#039;			=&gt;	&#039;inner&#039;		,
		&#039;foreignKey&#039;	=&gt;	&#039;album_id&#039;	,
	),
	array(
		&#039;table&#039; 		=&gt; 	&#039;comments&#039;	,
		&#039;alias&#039;			=&gt;	&#039;Comment&#039;	,
		&#039;type&#039;			=&gt;	&#039;inner&#039;		,
		&#039;foreignKey&#039;	=&gt;	&#039;photo_id&#039;	,
	),
)));

$data = $this-&gt;User-&gt;find( &#039;all&#039;, array( &#039;joins&#039; =&gt; array(
	array(
		&#039;table&#039;			=&gt;	&#039;albums&#039;			,
		&#039;alias&#039;			=&gt;	&#039;Album&#039;				,
		&#039;type&#039;			=&gt;	&#039;inner&#039;				,
		&#039;foreignKey&#039;	=&gt;	false				,
		&#039;conditions&#039;	=&gt;	array(
			&#039;User.id&#039;	=&gt;	&#039;Album.user_id&#039;		,
		)
	),
	array(
		&#039;table&#039;			=&gt;	&#039;photos&#039;			,
		&#039;alias&#039;			=&gt;	&#039;Photo&#039;				,
		&#039;type&#039;			=&gt;	&#039;inner&#039;				,
		&#039;foreignKey&#039;	=&gt;	false				,
		&#039;conditions&#039;	=&gt;	array(
			&#039;Album.id&#039;	=&gt;	&#039;Photo.album_id&#039;	,
		)
	),
	array(
		&#039;table&#039;			=&gt;	&#039;comments&#039;			,
		&#039;alias&#039;			=&gt;	&#039;Comment&#039;			,
		&#039;type&#039;			=&gt;	&#039;inner&#039;				,
		&#039;foreignKey&#039;	=&gt;	false				,
		&#039;conditions&#039;	=&gt;	array(
			&#039;Photo.id&#039;	=&gt;	&#039;Comment.photo_id&#039;	,
		)
	),
)));
&lt;/code&gt;

Both of these options *are untested* and may not work perfectly. I suggest you tweak the order of the conditions, or combine the foreignKey = &#039;foreignTable_id&#039; and the conditions array if you run into trouble. The SQL debugger is very useful.</description>
		<content:encoded><![CDATA[<p><code>I just checked and for me at least setting both recursive and contains is not needed. It seems the containable behavior sets it for you.</p><p>also a more elegant method for the same results would be do to some ad-hoc joins on the model-&gt;find as per <a href="http://bakery.cakephp.org/articles/view/quick-tip-doing-ad-hoc-joins-in-model-find" rel="nofollow">http://bakery.cakephp.org/articles/view/quick-tip-doing-ad-hoc-joins-in-model-find</a></p><p></code><code><br />$data = $this-&gt;User-&gt;find( 'all', array( 'joins' =&gt; array(<br />	array(<br />		'table' 		=&gt; 	'albums'	,<br />		'alias'			=&gt;	'Album'		,<br />		'type'			=&gt;	'inner'		,<br />		'foreignKey'	=&gt;	'user_id'	,<br />	),<br />	array(<br />		'table' 		=&gt; 	'photos'	,<br />		'alias'			=&gt;	'Photo'		,<br />		'type'			=&gt;	'inner'		,<br />		'foreignKey'	=&gt;	'album_id'	,<br />	),<br />	array(<br />		'table' 		=&gt; 	'comments'	,<br />		'alias'			=&gt;	'Comment'	,<br />		'type'			=&gt;	'inner'		,<br />		'foreignKey'	=&gt;	'photo_id'	,<br />	),<br />)));</p><p>$data = $this-&gt;User-&gt;find( 'all', array( 'joins' =&gt; array(<br />	array(<br />		'table'			=&gt;	'albums'			,<br />		'alias'			=&gt;	'Album'				,<br />		'type'			=&gt;	'inner'				,<br />		'foreignKey'	=&gt;	false				,<br />		'conditions'	=&gt;	array(<br />			'User.id'	=&gt;	'Album.user_id'		,<br />		)<br />	),<br />	array(<br />		'table'			=&gt;	'photos'			,<br />		'alias'			=&gt;	'Photo'				,<br />		'type'			=&gt;	'inner'				,<br />		'foreignKey'	=&gt;	false				,<br />		'conditions'	=&gt;	array(<br />			'Album.id'	=&gt;	'Photo.album_id'	,<br />		)<br />	),<br />	array(<br />		'table'			=&gt;	'comments'			,<br />		'alias'			=&gt;	'Comment'			,<br />		'type'			=&gt;	'inner'				,<br />		'foreignKey'	=&gt;	false				,<br />		'conditions'	=&gt;	array(<br />			'Photo.id'	=&gt;	'Comment.photo_id'	,<br />		)<br />	),<br />)));<br /></code></p>
<p>Both of these options *are untested* and may not work perfectly. I suggest you tweak the order of the conditions, or combine the foreignKey = &#8216;foreignTable_id&#8217; and the conditions array if you run into trouble. The SQL debugger is very useful.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jamie</title>
		<link>http://www.endyourif.com/cakephp-containable-statement-pitfalls/comment-page-1/#comment-56</link>
		<dc:creator>Jamie</dc:creator>
		<pubDate>Mon, 16 Mar 2009 21:07:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.endyourif.com/?p=227#comment-56</guid>
		<description>I believe so.  This seems to be the default setting on all of the projects that I have worked with, so I&#039;ve only had to turn it down from 2.</description>
		<content:encoded><![CDATA[<p><code>I believe so.  This seems to be the default setting on all of the projects that I have worked with, so I&#8217;ve only had to turn it down from 2.</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Leonardo</title>
		<link>http://www.endyourif.com/cakephp-containable-statement-pitfalls/comment-page-1/#comment-54</link>
		<dc:creator>Leonardo</dc:creator>
		<pubDate>Mon, 16 Mar 2009 13:07:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.endyourif.com/?p=227#comment-54</guid>
		<description>Do i have to set &quot;recursive&quot;=&gt;2 for works well?!</description>
		<content:encoded><![CDATA[<p><code>Do i have to set &#8220;recursive&#8221;=&gt;2 for works well?!</code></p>
]]></content:encoded>
	</item>
</channel>
</rss>
