title: How to update a jointable in CakePHP, manually
body: <p>I am sort of a newbie with CakePHP.
  I have two tables: contacts and tags, and an HABTM table contacts_tags. User should be able to add tags as people can do in delicious.com. they get a list of tags as they type. They can also add new tags just by typing them. I want to check the tags table to see which tags are already present and which are not. The tags which are new should be added to the table and the insert ids are appended to an array. Then I want to use these tag ids to update the contacts_tags table. That's it. These are the two functions I have created:</p>
  
  <pre><code> /**
  this function checks for existing tags and creates new tags
  @params string (of comma separated tags)
  @return array (of IDs)
  **/
  function saveAndCreateTags($tags){
      $tags = explode(",", $tags); //create array of tags
      $idArray = array();
      foreach($tags as $tag) {
          $count = $this-&gt;find('count', array('conditions' =&gt; array('name' =&gt; $tag)));
          if($count === 0) {
              $this-&gt;create();
              if($this-&gt;save($tag)) {
              $idArray[] = $this-&gt;getInsertID();
              }
          }
          else {
              $idArray[] = $this-&gt;getID();
          }
      }
      return $idArray;
  }
  
  /**
  this function updates the relational table
  @params array (this array is returned by saveAndCreateTags function
  @params int (id of the contact)
  **/
  function updateContactTagsTable($idArray, $contactId){
      foreach($idArray as $tagId) {
          $count = $this-&gt;ContactTag-&gt;hasAny(array('tag_id' =&gt; $tagId, 'contact_id' =&gt; $contactId));
          if($count === 0) {
              ();
              $this-&gt;ContactTag-&gt;save(array('contact_id' =&gt; $contactId, 'tag_id' =&gt; $tagId));
          }
      }       
  }
  </code></pre>
  
  <p>Neither of $this->ContactTag->hasAny, $this->ContactTag->create, $this->ContactTag->save is working... Am I missing something?</p>