<?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 TreeCounterCacheBehavior plugin</title>
	<atom:link href="http://www.neilcrookes.com/2010/01/09/cakephp-treecountercachebehavior-plugin/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.neilcrookes.com/2010/01/09/cakephp-treecountercachebehavior-plugin/</link>
	<description>Learnings and Teachings on Web Application Development &#38; CakePHP</description>
	<lastBuildDate>Wed, 25 Apr 2012 09:53:39 +0200</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
	<item>
		<title>By: Neil Crookes &#8212; Several great CakePHP Plugins (high quality)! &#124; MKfmn &#124; Matt Kaufman</title>
		<link>http://www.neilcrookes.com/2010/01/09/cakephp-treecountercachebehavior-plugin/comment-page-1/#comment-15150</link>
		<dc:creator>Neil Crookes &#8212; Several great CakePHP Plugins (high quality)! &#124; MKfmn &#124; Matt Kaufman</dc:creator>
		<pubDate>Sat, 23 Jul 2011 15:54:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.neilcrookes.com/?p=196#comment-15150</guid>
		<description>[...] each node in the tree. Packaged as a plugin with a fixture and unit tests with 100% code coverage.  6 Comments Filed under: CakePHP  (1 votes, average: 4.00 out of 5, [...]</description>
		<content:encoded><![CDATA[<p>[...] each node in the tree. Packaged as a plugin with a fixture and unit tests with 100% code coverage.  6 Comments Filed under: CakePHP  (1 votes, average: 4.00 out of 5, [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ernest</title>
		<link>http://www.neilcrookes.com/2010/01/09/cakephp-treecountercachebehavior-plugin/comment-page-1/#comment-10313</link>
		<dc:creator>Ernest</dc:creator>
		<pubDate>Wed, 17 Nov 2010 12:53:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.neilcrookes.com/?p=196#comment-10313</guid>
		<description>Hi, 

and first of all thanks for posting your work, it&#039;s been really useful!

about the code HabtmCounterCache behaviour on github (https://gist.github.com/235652/d196add592288c8ce5d4bd9edf9b19c89bc6fee7).

I fixed one infinite loop that was happening in my app.

I post here it for if someone has the same problem....

on line 357:
$model-&gt;{$habtmAlias}-&gt;save(array(

      $habtmAlias =&gt; array(
        &#039;id&#039; =&gt; $habtmId,
        $settings[&#039;counterCache&#039;] =&gt; $count,
      ),
    ));

was creating an infinite loop in my app. using cake 3.5

if someone has the same problem can fix it changing it for this:

    $model-&gt;{$habtmAlias}-&gt;id = $habtmId;
    $model-&gt;{$habtmAlias}-&gt;saveField($settings[&#039;counterCache&#039;], $count, array(
                &#039;validate&#039; =&gt; false,
                &#039;callbacks&#039; =&gt; false
            ));</description>
		<content:encoded><![CDATA[<p>Hi, </p>
<p>and first of all thanks for posting your work, it&#8217;s been really useful!</p>
<p>about the code HabtmCounterCache behaviour on github (<a href="https://gist.github.com/235652/d196add592288c8ce5d4bd9edf9b19c89bc6fee7" rel="nofollow">https://gist.github.com/235652/d196add592288c8ce5d4bd9edf9b19c89bc6fee7</a>).</p>
<p>I fixed one infinite loop that was happening in my app.</p>
<p>I post here it for if someone has the same problem&#8230;.</p>
<p>on line 357:<br />
$model-&gt;{$habtmAlias}-&gt;save(array(</p>
<p>      $habtmAlias =&gt; array(<br />
        &#8216;id&#8217; =&gt; $habtmId,<br />
        $settings['counterCache'] =&gt; $count,<br />
      ),<br />
    ));</p>
<p>was creating an infinite loop in my app. using cake 3.5</p>
<p>if someone has the same problem can fix it changing it for this:</p>
<p>    $model-&gt;{$habtmAlias}-&gt;id = $habtmId;<br />
    $model-&gt;{$habtmAlias}-&gt;saveField($settings['counterCache'], $count, array(<br />
                &#8216;validate&#8217; =&gt; false,<br />
                &#8216;callbacks&#8217; =&gt; false<br />
            ));</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Neil Crookes</title>
		<link>http://www.neilcrookes.com/2010/01/09/cakephp-treecountercachebehavior-plugin/comment-page-1/#comment-7604</link>
		<dc:creator>Neil Crookes</dc:creator>
		<pubDate>Sun, 21 Feb 2010 20:29:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.neilcrookes.com/?p=196#comment-7604</guid>
		<description>@Jesús, thanks for the comment. I&#039;ll check out your issues.</description>
		<content:encoded><![CDATA[<p>@Jesús, thanks for the comment. I&#8217;ll check out your issues.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jesús Ángel</title>
		<link>http://www.neilcrookes.com/2010/01/09/cakephp-treecountercachebehavior-plugin/comment-page-1/#comment-7597</link>
		<dc:creator>Jesús Ángel</dc:creator>
		<pubDate>Sun, 21 Feb 2010 12:10:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.neilcrookes.com/?p=196#comment-7597</guid>
		<description>Hi!

I have seen your HabtmCounterCache behaviour on github (https://gist.github.com/235652/d196add592288c8ce5d4bd9edf9b19c89bc6fee7).

I think there are some bugs in that code:

Line 246
$model-&gt;data[$habtmAlias][$habtmAlias] may be empty what causes warning on array_merge in the line 258. You should test for empty value in the line 246:

if (!isset($model-&gt;data[$habtmAlias][$habtmAlias]) &#124;&#124; empty($model-&gt;data[$habtmAlias][$habtmAlias])) {

Line 357
By default, save method check for validation rules. But in line 357 we only want to save/update some model fields, so we should disable validation:

$model-&gt;{$habtmAlias}-&gt;save(array(
          $habtmAlias =&gt; array(
            &#039;id&#039; =&gt; $habtmId,
            $settings[&#039;counterCache&#039;] =&gt; $count,
          ),
        ),
        false
        );

Hope this helps.

Thanks for sharing your code!</description>
		<content:encoded><![CDATA[<p>Hi!</p>
<p>I have seen your HabtmCounterCache behaviour on github (<a href="https://gist.github.com/235652/d196add592288c8ce5d4bd9edf9b19c89bc6fee7" rel="nofollow">https://gist.github.com/235652/d196add592288c8ce5d4bd9edf9b19c89bc6fee7</a>).</p>
<p>I think there are some bugs in that code:</p>
<p>Line 246<br />
$model-&gt;data[$habtmAlias][$habtmAlias] may be empty what causes warning on array_merge in the line 258. You should test for empty value in the line 246:</p>
<p>if (!isset($model-&gt;data[$habtmAlias][$habtmAlias]) || empty($model-&gt;data[$habtmAlias][$habtmAlias])) {</p>
<p>Line 357<br />
By default, save method check for validation rules. But in line 357 we only want to save/update some model fields, so we should disable validation:</p>
<p>$model-&gt;{$habtmAlias}-&gt;save(array(<br />
          $habtmAlias =&gt; array(<br />
            &#8216;id&#8217; =&gt; $habtmId,<br />
            $settings['counterCache'] =&gt; $count,<br />
          ),<br />
        ),<br />
        false<br />
        );</p>
<p>Hope this helps.</p>
<p>Thanks for sharing your code!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Neil Crookes</title>
		<link>http://www.neilcrookes.com/2010/01/09/cakephp-treecountercachebehavior-plugin/comment-page-1/#comment-7044</link>
		<dc:creator>Neil Crookes</dc:creator>
		<pubDate>Sat, 16 Jan 2010 08:24:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.neilcrookes.com/?p=196#comment-7044</guid>
		<description>@Ryan, you are absolutely right...

From twitter:

@AD7six: why have a (total)child_count field at all. no-of-children = (rght - lft -1)/2 .
@neilcrookes: ah, I remember now, it&#039;s for when I add scope functionality
@neilcrookes: when I say remember, I mean, that&#039;s the excuse I just came up with for being too dumb to realise no-of-children = (rght - lft -1)/2</description>
		<content:encoded><![CDATA[<p>@Ryan, you are absolutely right&#8230;</p>
<p>From twitter:</p>
<p>@AD7six: why have a (total)child_count field at all. no-of-children = (rght &#8211; lft -1)/2 .<br />
@neilcrookes: ah, I remember now, it&#8217;s for when I add scope functionality<br />
@neilcrookes: when I say remember, I mean, that&#8217;s the excuse I just came up with for being too dumb to realise no-of-children = (rght &#8211; lft -1)/2</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan Rose</title>
		<link>http://www.neilcrookes.com/2010/01/09/cakephp-treecountercachebehavior-plugin/comment-page-1/#comment-7037</link>
		<dc:creator>Ryan Rose</dc:creator>
		<pubDate>Fri, 15 Jan 2010 22:27:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.neilcrookes.com/?p=196#comment-7037</guid>
		<description>You could also use some quick math to find out how many children the node has based on the left and right values:

$numberOfTotalChildren = ($result[$model][$right] - $result[$model][$left] - 1) / 2;</description>
		<content:encoded><![CDATA[<p>You could also use some quick math to find out how many children the node has based on the left and right values:</p>
<p>$numberOfTotalChildren = ($result[$model][$right] &#8211; $result[$model][$left] &#8211; 1) / 2;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: CakePHP : signets remarquables du 07/01/2010 au 11/01/2010 &#124; Cherry on the...</title>
		<link>http://www.neilcrookes.com/2010/01/09/cakephp-treecountercachebehavior-plugin/comment-page-1/#comment-6935</link>
		<dc:creator>CakePHP : signets remarquables du 07/01/2010 au 11/01/2010 &#124; Cherry on the...</dc:creator>
		<pubDate>Mon, 11 Jan 2010 19:06:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.neilcrookes.com/?p=196#comment-6935</guid>
		<description>[...] Neil Crookes &#187; CakePHP TreeCounterCacheBehavior plugin [...]</description>
		<content:encoded><![CDATA[<p>[...] Neil Crookes &raquo; CakePHP TreeCounterCacheBehavior plugin [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>

