<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Working with HABTM associations</title>
	<atom:link href="http://rossoft.wordpress.com/2006/08/23/working-with-habtm-associations/feed/" rel="self" type="application/rss+xml" />
	<link>http://rossoft.wordpress.com/2006/08/23/working-with-habtm-associations/</link>
	<description>CakePHP Tips &#38; Tricks</description>
	<lastBuildDate>Tue, 08 Dec 2009 11:58:14 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Arvind K Thakur</title>
		<link>http://rossoft.wordpress.com/2006/08/23/working-with-habtm-associations/#comment-17523</link>
		<dc:creator>Arvind K Thakur</dc:creator>
		<pubDate>Mon, 09 Feb 2009 05:13:10 +0000</pubDate>
		<guid isPermaLink="false">http://rossoft.wordpress.com/2006/08/23/working-with-habtm-associations/#comment-17523</guid>
		<description>As of latest release 1.2.1.8004 do we still need to use this model class for HABTM associations?</description>
		<content:encoded><![CDATA[<p>As of latest release 1.2.1.8004 do we still need to use this model class for HABTM associations?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Recursos para iniciarse con CakePHP &#124; Mareos de un Geek</title>
		<link>http://rossoft.wordpress.com/2006/08/23/working-with-habtm-associations/#comment-17505</link>
		<dc:creator>Recursos para iniciarse con CakePHP &#124; Mareos de un Geek</dc:creator>
		<pubDate>Fri, 21 Nov 2008 09:04:36 +0000</pubDate>
		<guid isPermaLink="false">http://rossoft.wordpress.com/2006/08/23/working-with-habtm-associations/#comment-17505</guid>
		<description>[...] Trabajando con las asociaciones HABTM - Visitar [...]</description>
		<content:encoded><![CDATA[<p>[...] Trabajando con las asociaciones HABTM &#8211; Visitar [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: CakePHP Tutorials &#124; lonerunners.net</title>
		<link>http://rossoft.wordpress.com/2006/08/23/working-with-habtm-associations/#comment-17497</link>
		<dc:creator>CakePHP Tutorials &#124; lonerunners.net</dc:creator>
		<pubDate>Wed, 29 Oct 2008 15:16:13 +0000</pubDate>
		<guid isPermaLink="false">http://rossoft.wordpress.com/2006/08/23/working-with-habtm-associations/#comment-17497</guid>
		<description>[...] How to use the official CakePHP test suite [...]</description>
		<content:encoded><![CDATA[<p>[...] How to use the official CakePHP test suite [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mzee.richo</title>
		<link>http://rossoft.wordpress.com/2006/08/23/working-with-habtm-associations/#comment-17492</link>
		<dc:creator>mzee.richo</dc:creator>
		<pubDate>Tue, 14 Oct 2008 14:39:09 +0000</pubDate>
		<guid isPermaLink="false">http://rossoft.wordpress.com/2006/08/23/working-with-habtm-associations/#comment-17492</guid>
		<description>Nice stuff bro . looking through and liking it</description>
		<content:encoded><![CDATA[<p>Nice stuff bro . looking through and liking it</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tutoriales de CakePHP</title>
		<link>http://rossoft.wordpress.com/2006/08/23/working-with-habtm-associations/#comment-14349</link>
		<dc:creator>Tutoriales de CakePHP</dc:creator>
		<pubDate>Tue, 18 Sep 2007 00:30:47 +0000</pubDate>
		<guid isPermaLink="false">http://rossoft.wordpress.com/2006/08/23/working-with-habtm-associations/#comment-14349</guid>
		<description>[...] Trabajando con las asociaciones HABTM - Visitar [...]</description>
		<content:encoded><![CDATA[<p>[...] Trabajando con las asociaciones HABTM &#8211; Visitar [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tutoriales muy útiles de CakePHP</title>
		<link>http://rossoft.wordpress.com/2006/08/23/working-with-habtm-associations/#comment-14329</link>
		<dc:creator>Tutoriales muy útiles de CakePHP</dc:creator>
		<pubDate>Mon, 17 Sep 2007 12:00:36 +0000</pubDate>
		<guid isPermaLink="false">http://rossoft.wordpress.com/2006/08/23/working-with-habtm-associations/#comment-14329</guid>
		<description>[...] Trabajando con las asociaciones HABTM - Visitar [...]</description>
		<content:encoded><![CDATA[<p>[...] Trabajando con las asociaciones HABTM &#8211; Visitar [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: TJ</title>
		<link>http://rossoft.wordpress.com/2006/08/23/working-with-habtm-associations/#comment-14086</link>
		<dc:creator>TJ</dc:creator>
		<pubDate>Mon, 10 Sep 2007 17:20:15 +0000</pubDate>
		<guid isPermaLink="false">http://rossoft.wordpress.com/2006/08/23/working-with-habtm-associations/#comment-14086</guid>
		<description>@#$*#&amp;!
s/@return array Data array with current HABTM association intact/@return boolean Success/

Post also clobbered the indention :(</description>
		<content:encoded><![CDATA[<p>@#$*#&amp;!<br />
s/@return array Data array with current HABTM association intact/@return boolean Success/</p>
<p>Post also clobbered the indention <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: TJ</title>
		<link>http://rossoft.wordpress.com/2006/08/23/working-with-habtm-associations/#comment-14085</link>
		<dc:creator>TJ</dc:creator>
		<pubDate>Mon, 10 Sep 2007 17:17:30 +0000</pubDate>
		<guid isPermaLink="false">http://rossoft.wordpress.com/2006/08/23/working-with-habtm-associations/#comment-14085</guid>
		<description>I add this function to my code - hope someone finds it useful.  I use this for multiple select&#039;s, where I had to both add all selected values and delete all unselected values.  I just took the logic from the add/delete functions and combined them, but there&#039;s only 1 query and 1 save() call.  This reduces the number of calls to the DB by about 1/2.  It also will only save each association once (I was seeing attempts to save duplicate entries in the join table.  DB won&#039;t allow it, but why waste the effort?).   

    /**
     * @param integer $id The id of the record in this model
     * @param mixed $assoc_name The name of the HABTM association
     * @param mixed $save_id The associated id or an array of id&#039;s to be saved
     * @param mixed $delete_id The associated id or an array of id&#039;s to be removed
     * @return array Data array with current HABTM association intact
     */
    function updateAssoc($id,$assoc_name,$save_id=null,$delete_id=null)
    {
        if ( $save_id &#124;&#124; $delete_id ) {
            $data=$this-&gt;_auxAssoc($id,$assoc_name);
            if ($save_id) {
                if (!is_array($save_id)) {
                    $save_id=array($save_id);
                }
                $data[$assoc_name][$assoc_name]= $data[$assoc_name][$assoc_name] + $save_id;
            }
            if ($delete_id) {
                if (!is_array($delete_id)) {
                    $delete_id=array($delete_id);
                }
            } else {
                $delete_id = array();
            }
            $result=array();
            foreach ($data[$assoc_name][$assoc_name] as $id)
            {
                if (!in_array($id, $delete_id)) {
                    $result[$id]=$id;
                }
            }
            $data[$assoc_name][$assoc_name]=$result;
            return $this-&gt;save($data, true);
        }
    }</description>
		<content:encoded><![CDATA[<p>I add this function to my code &#8211; hope someone finds it useful.  I use this for multiple select&#8217;s, where I had to both add all selected values and delete all unselected values.  I just took the logic from the add/delete functions and combined them, but there&#8217;s only 1 query and 1 save() call.  This reduces the number of calls to the DB by about 1/2.  It also will only save each association once (I was seeing attempts to save duplicate entries in the join table.  DB won&#8217;t allow it, but why waste the effort?).   </p>
<p>    /**<br />
     * @param integer $id The id of the record in this model<br />
     * @param mixed $assoc_name The name of the HABTM association<br />
     * @param mixed $save_id The associated id or an array of id&#8217;s to be saved<br />
     * @param mixed $delete_id The associated id or an array of id&#8217;s to be removed<br />
     * @return array Data array with current HABTM association intact<br />
     */<br />
    function updateAssoc($id,$assoc_name,$save_id=null,$delete_id=null)<br />
    {<br />
        if ( $save_id || $delete_id ) {<br />
            $data=$this-&gt;_auxAssoc($id,$assoc_name);<br />
            if ($save_id) {<br />
                if (!is_array($save_id)) {<br />
                    $save_id=array($save_id);<br />
                }<br />
                $data[$assoc_name][$assoc_name]= $data[$assoc_name][$assoc_name] + $save_id;<br />
            }<br />
            if ($delete_id) {<br />
                if (!is_array($delete_id)) {<br />
                    $delete_id=array($delete_id);<br />
                }<br />
            } else {<br />
                $delete_id = array();<br />
            }<br />
            $result=array();<br />
            foreach ($data[$assoc_name][$assoc_name] as $id)<br />
            {<br />
                if (!in_array($id, $delete_id)) {<br />
                    $result[$id]=$id;<br />
                }<br />
            }<br />
            $data[$assoc_name][$assoc_name]=$result;<br />
            return $this-&gt;save($data, true);<br />
        }<br />
    }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: TJ</title>
		<link>http://rossoft.wordpress.com/2006/08/23/working-with-habtm-associations/#comment-14006</link>
		<dc:creator>TJ</dc:creator>
		<pubDate>Sat, 08 Sep 2007 07:05:58 +0000</pubDate>
		<guid isPermaLink="false">http://rossoft.wordpress.com/2006/08/23/working-with-habtm-associations/#comment-14006</guid>
		<description>This is awesome, and I&#039;m grateful for it.  One suggestion: why not merge both addAssoc() and deleteAssoc() into one function with an additional argument, something like this:

updateAssoc($id, &#039;Tag&#039;, array(id&#039;s to save), array(id&#039;s to delete))

I will do this for my project.  Perhaps it&#039;s just due to quirks of my implementation, but I find myself calling both functions back-to-back in many cases.  This would permit a single save() call to the DB, rather than a call to remove some items followed by a call to add items.</description>
		<content:encoded><![CDATA[<p>This is awesome, and I&#8217;m grateful for it.  One suggestion: why not merge both addAssoc() and deleteAssoc() into one function with an additional argument, something like this:</p>
<p>updateAssoc($id, &#8216;Tag&#8217;, array(id&#8217;s to save), array(id&#8217;s to delete))</p>
<p>I will do this for my project.  Perhaps it&#8217;s just due to quirks of my implementation, but I find myself calling both functions back-to-back in many cases.  This would permit a single save() call to the DB, rather than a call to remove some items followed by a call to add items.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sonia</title>
		<link>http://rossoft.wordpress.com/2006/08/23/working-with-habtm-associations/#comment-10096</link>
		<dc:creator>sonia</dc:creator>
		<pubDate>Tue, 03 Jul 2007 11:17:30 +0000</pubDate>
		<guid isPermaLink="false">http://rossoft.wordpress.com/2006/08/23/working-with-habtm-associations/#comment-10096</guid>
		<description>hi</description>
		<content:encoded><![CDATA[<p>hi</p>
]]></content:encoded>
	</item>
</channel>
</rss>
