title: CakePHP HABTM Association not working
body: <p>I've been trying to find an answer to my problem for hours. I am currently working with cakePHP 2.4.</p>
  
  <p>I have two models, Users and Groups. I have created the following associations for each:
  (User.php)</p>
  
  <blockquote>
    <p>public $hasAndBelongsToMany = array(</p>
  
  <pre><code>   'Group' =&gt;
          array(
              'className' =&gt; 'Group',
              'joinTable' =&gt; 'groups_users',
              'foreignKey' =&gt; 'user_id',
              'associationForeignKey' =&gt; 'group_id',
              'unique' =&gt; true,
          )
  );  
  </code></pre>
  </blockquote>
  
  <p>and (Group.php):</p>
  
  <blockquote>
    <p>public $hasAndBelongsToMany  = array(</p>
  
  <pre><code>    'GroupUser' =&gt;
          array(
              'className' =&gt; 'User',
              'joinTable' =&gt; 'groups_users',
              'foreignKey' =&gt; 'group_id',
              'associationForeignKey' =&gt; 'user_id',
              'unique' =&gt; true,
          )
  );
  </code></pre>
  </blockquote>
  
  <p>The reason I use GroupUser and not "User" is I get an error because I have already used "User for some other relation.</p>
  
  <p>My form looks like this:</p>
  
  <blockquote>
    <p>echo $this->Form->create('Group', array('controller' => 'group','action' => 'add'));</p>
    
    <p>echo $this->Form->input('User.id', array('type' => 'hidden', 'value' => $authUser['id']);</p>
    
    <p>echo $this->Form->input('Group.address');</p>
    
    <p>echo $this->Form->end(__('Save', true));</p>
  </blockquote>
  
  <p>I also have a table called groups_users with "id", "user_id" and "group_id"</p>
  
  <p>When I submit the form, it created the new Group and saves the data, but the association is not created.</p>
  
  <p>I tried manually filling a groups_users record with an existing user_id and group_id but still, when I use find(All), it doesn't find the expected association like it should according to the books.</p>
  
  <p>I debugged the array that is being saved and it looks like this:</p>
  
  <pre><code>Array
  (
  [User] =&gt; Array
      (
          [user_id] =&gt; 39
      )
  [Group] =&gt; Array
      (
          [address] =&gt; asdasd, San Antonio, Texas 78233, EE. UU.
      )
  
  
  
  )
  </code></pre>
  
  <p>This is the code in my GroupsController add function:</p>
  
  <pre><code>if ($this-&gt;Group-&gt;save($this-&gt;request-&gt;data)) {
  // redirect or do something
  }
  </code></pre>
  
  <p>I have tried changing the array to work with saveAll like in the books, still only created new record but no association. And as I said, I mannually created a record and tried finding it and it wouldn't find it anyway. </p>