title: CakePHP save two models, second based on first
body: <p>I have the following association:</p>
  
  <p>Group hasAndBelongsToMany User, with the groups_users join table.</p>
  
  <p>When I create a new group, I want to add to the join table the founder of the group.</p>
  
  <p>My $this->data array looks like:</p>
  
  <pre><code>Array
       (
  [Group] =&gt; Array
      (
          [name] =&gt; seyufgsduifsj
          [access] =&gt; 2
          [founder_id] =&gt; 3
          [random_key] =&gt; I6XC7uMTelpTSdq8DbtLPjqubiF7s6Pn
      )
  
  [GroupsUser] =&gt; Array
      (
          [user_id] =&gt; 3
          [group_role_id] =&gt; 1
          [random_key] =&gt; PZsDZXcoCTHw1IuvqsfURVpPX6AcZ3r2
      )
  </code></pre>
  
  <p>)</p>
  
  <p>I tried with save() and saveAll(), but it would add only the group in the groups table and not the user-group association.</p>
  
  <p>So, basically, I have an add form where the user fills in the group name and access. Then, if the data validates, I add a couple of more field values to the group array (like random_key) and to the join table array (like user_id and group_role_id). I want Cake to save the group first, take its id, update the join table array with the proper group_id, and then save this second array too.</p>
  
  <p>Is this possible in a straight-forward way, or do I have to write two consequent save() methods, for the second one providing the last inserted id in the first one?</p>
  
  <p>Thanks!</p>