title: CakePHP hasAndBelogsToMany using save() vs. saveAll()
body: <p>I am using a very intrinsic database with a CakePHP application and so far my multi-models views and controllers are working fine. I have a singular table (<code>Entity</code>) that have it's <code>id</code> on several other tables as the Foreign Key <code>entity_id</code></p>
  
  <p>Some tables are one to one relations (Like a <code>Company</code> is one <code>Entity</code>) and some are one to many (<code>Entity</code> can have several <code>Addresses</code>) and so on.</p>
  
  <p><em>I won't/can't change the database model</em>, so this is the structure.</p>
  
  <p>I have been using <code>saveAll()</code> to save data on those tables with input names like:</p>
  
  <pre><code>Entity.type='x' (hidden inside the view)
  Company.name
  Address.0.street
  Address.0.city
  Address.1.street
  Address.1.city
  
  ... and so on ...
  </code></pre>
  
  <p>and my save all is doing all the hard job, <code>BEGIN TRANSACTION</code>, all <code>INSERT</code>s and a final <code>COMMIT</code> ...</p>
  
  <p>But now I've created a <code>EntityCategory</code> that is a n to n  relation and created the full <code>HABTM</code> relation inside the model.</p>
  
  <p>It works when I <code>save()</code> it but just the <code>HABTM</code> relation, and it saves everthing when I use <code>saveAll()</code> (just as before) except for the <code>HABTM</code> relation.</p>
  
  <p>Am I missing something ? How I make this work correctly ? I am using the following code today:</p>
  
  <pre><code>if (!empty($this-&gt;data)) {
    $this-&gt;Entity-&gt;saveAll($this-&gt;data);
    $this-&gt;Entity-&gt;save($this-&gt;data);
  }
  </code></pre>
  
  <p>The <code>saveAll()</code> saves all data in several tables, saves the id in <code>Entity-&gt;id</code> and the <code>save()</code> saves the <code>HABTM</code> relations, but I am not sure if it is correct or if it can bring me problems if I change some structure/model.</p>
  
  <p>Is this the best way to use it? Is there a <em>correct</em> way to save that relations inside CakePHP ? What your experience/knowledge can tell me ?</p>