<?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: Editing hasAndBelongsToMany (HABTM) Relationships in CakePHP</title>
	<atom:link href="http://shepherdweb.com/2006/08/21/editing-hasandbelongstomany-habtm-relationships-in-cakephp/feed/" rel="self" type="application/rss+xml" />
	<link>http://shepherdweb.com/2006/08/21/editing-hasandbelongstomany-habtm-relationships-in-cakephp/</link>
	<description>Shane Shepherd: web design and development; music</description>
	<pubDate>Fri, 21 Nov 2008 10:06:29 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
		<item>
		<title>By: Gianni</title>
		<link>http://shepherdweb.com/2006/08/21/editing-hasandbelongstomany-habtm-relationships-in-cakephp/#comment-22168</link>
		<dc:creator>Gianni</dc:creator>
		<pubDate>Fri, 22 Aug 2008 08:48:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.shepherdweb.com/2006/08/21/editing-hasandbelongstomany-habtm-relationships-in-cakephp/#comment-22168</guid>
		<description>Hi. 
Thanks is very helpfull.

Is this possible with checkboxes instead of multi-select ?

I've tried to do it with your code but it doesn't work...</description>
		<content:encoded><![CDATA[<p>Hi.<br />
Thanks is very helpfull.</p>
<p>Is this possible with checkboxes instead of multi-select ?</p>
<p>I&#8217;ve tried to do it with your code but it doesn&#8217;t work&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Palivoda IT Solutions &#187; Blog Archive &#187; HABTM with multiple select in CakePHP 1.2</title>
		<link>http://shepherdweb.com/2006/08/21/editing-hasandbelongstomany-habtm-relationships-in-cakephp/#comment-21682</link>
		<dc:creator>Palivoda IT Solutions &#187; Blog Archive &#187; HABTM with multiple select in CakePHP 1.2</dc:creator>
		<pubDate>Wed, 09 Apr 2008 07:56:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.shepherdweb.com/2006/08/21/editing-hasandbelongstomany-habtm-relationships-in-cakephp/#comment-21682</guid>
		<description>[...] Refferences: 1. HABTM Add &#38; Delete Behavior 2. Editing hasAndBelongsToMany (HABTM) Relationships in CakePHP [...]</description>
		<content:encoded><![CDATA[<p>[...] Refferences: 1. HABTM Add &#38; Delete Behavior 2. Editing hasAndBelongsToMany (HABTM) Relationships in CakePHP [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: toyosystem &#124; CakePHP::HABTMの編集画面を作る</title>
		<link>http://shepherdweb.com/2006/08/21/editing-hasandbelongstomany-habtm-relationships-in-cakephp/#comment-19796</link>
		<dc:creator>toyosystem &#124; CakePHP::HABTMの編集画面を作る</dc:creator>
		<pubDate>Wed, 13 Feb 2008 03:48:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.shepherdweb.com/2006/08/21/editing-hasandbelongstomany-habtm-relationships-in-cakephp/#comment-19796</guid>
		<description>[...] shepherdweb 上記サイトのとおりにやってください！ [...]</description>
		<content:encoded><![CDATA[<p>[...] shepherdweb 上記サイトのとおりにやってください！ [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David</title>
		<link>http://shepherdweb.com/2006/08/21/editing-hasandbelongstomany-habtm-relationships-in-cakephp/#comment-19259</link>
		<dc:creator>David</dc:creator>
		<pubDate>Fri, 30 Nov 2007 15:02:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.shepherdweb.com/2006/08/21/editing-hasandbelongstomany-habtm-relationships-in-cakephp/#comment-19259</guid>
		<description>Very helpful, thank you.

I used the cake-defined _selectedArray() controller method in order to get an array with the selected elements of the multiple select instead of your getSelectedItems() function.

It also seems more adequate as selectTag() needs only the keys of the selected options rather than ids=&#62;names.

Regards</description>
		<content:encoded><![CDATA[<p>Very helpful, thank you.</p>
<p>I used the cake-defined _selectedArray() controller method in order to get an array with the selected elements of the multiple select instead of your getSelectedItems() function.</p>
<p>It also seems more adequate as selectTag() needs only the keys of the selected options rather than ids=&gt;names.</p>
<p>Regards</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jas</title>
		<link>http://shepherdweb.com/2006/08/21/editing-hasandbelongstomany-habtm-relationships-in-cakephp/#comment-18704</link>
		<dc:creator>jas</dc:creator>
		<pubDate>Thu, 15 Nov 2007 04:44:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.shepherdweb.com/2006/08/21/editing-hasandbelongstomany-habtm-relationships-in-cakephp/#comment-18704</guid>
		<description>ran into the same problems as Steve.  The solutions here cover saving the array and populating the default items but an unsuccessful save still lost the items in my case.  The handling of these HABTM default selections seems extremely inelegant.. I sincerely hope future versions will make this a little more straightforward.

My fix was the following (replace Blogentry with post and keyword with tag as appropriate):

  function edit($id = null) {
    $this-&#62;set("keywords", $this-&#62;Blogentry-&#62;Keyword-&#62;generateList(null, "keyword ASC", null, '{n}.Keyword.id', '{n}.Keyword.keyword');

    if (empty($this-&#62;data)) {
      $this-&#62;Blogentry-&#62;id = $id;
      $this-&#62;data = $this-&#62;Blogentry-&#62;read();
      $this-&#62;set('selected_keywords', array_keys($this-&#62;getSelectedItems($this-&#62;data['Keyword'], 'id', 'keyword')));
    } else {                 
      if ($this-&#62;Blogentry-&#62;save($this-&#62;data)) {
        $this-&#62;flash('Your post has been updated.','/blogentries');
      } else {
        $this-&#62;set('selected_keywords', $this-&#62;data['Keyword']['Keyword']);
        $this-&#62;set('errorMessage', 'Please correct errors below.');
      }
    }
  }</description>
		<content:encoded><![CDATA[<p>ran into the same problems as Steve.  The solutions here cover saving the array and populating the default items but an unsuccessful save still lost the items in my case.  The handling of these HABTM default selections seems extremely inelegant.. I sincerely hope future versions will make this a little more straightforward.</p>
<p>My fix was the following (replace Blogentry with post and keyword with tag as appropriate):</p>
<p>  function edit($id = null) {<br />
    $this-&gt;set(&#8221;keywords&#8221;, $this-&gt;Blogentry-&gt;Keyword-&gt;generateList(null, &#8220;keyword ASC&#8221;, null, &#8216;{n}.Keyword.id&#8217;, &#8216;{n}.Keyword.keyword&#8217;);</p>
<p>    if (empty($this-&gt;data)) {<br />
      $this-&gt;Blogentry-&gt;id = $id;<br />
      $this-&gt;data = $this-&gt;Blogentry-&gt;read();<br />
      $this-&gt;set(&#8217;selected_keywords&#8217;, array_keys($this-&gt;getSelectedItems($this-&gt;data['Keyword'], &#8216;id&#8217;, &#8216;keyword&#8217;)));<br />
    } else {<br />
      if ($this-&gt;Blogentry-&gt;save($this-&gt;data)) {<br />
        $this-&gt;flash(&#8217;Your post has been updated.&#8217;,'/blogentries&#8217;);<br />
      } else {<br />
        $this-&gt;set(&#8217;selected_keywords&#8217;, $this-&gt;data['Keyword']['Keyword']);<br />
        $this-&gt;set(&#8217;errorMessage&#8217;, &#8216;Please correct errors below.&#8217;);<br />
      }<br />
    }<br />
  }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shane</title>
		<link>http://shepherdweb.com/2006/08/21/editing-hasandbelongstomany-habtm-relationships-in-cakephp/#comment-6856</link>
		<dc:creator>Shane</dc:creator>
		<pubDate>Thu, 22 Mar 2007 22:01:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.shepherdweb.com/2006/08/21/editing-hasandbelongstomany-habtm-relationships-in-cakephp/#comment-6856</guid>
		<description>@Steve - You are too kind. :)</description>
		<content:encoded><![CDATA[<p>@Steve - You are too kind. <img src='http://shepherdweb.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve</title>
		<link>http://shepherdweb.com/2006/08/21/editing-hasandbelongstomany-habtm-relationships-in-cakephp/#comment-6827</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Thu, 22 Mar 2007 18:56:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.shepherdweb.com/2006/08/21/editing-hasandbelongstomany-habtm-relationships-in-cakephp/#comment-6827</guid>
		<description>Shane, don't count on it - believe me I spent hours searching. Despite what some of the experts in the google group say, there's nothing in the documentation that's remotely as helpful as the info on this page.</description>
		<content:encoded><![CDATA[<p>Shane, don&#8217;t count on it - believe me I spent hours searching. Despite what some of the experts in the google group say, there&#8217;s nothing in the documentation that&#8217;s remotely as helpful as the info on this page.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
