title: Updating rows over 2 tables
body: <p>I am having problems updating 2 tables with related models. I can get 1 table to be edited on its own.  I have checked around the docs and here and I cant find this simple answer as yet.</p>
  
  <p>What I get is a new row and not an edited row. </p>
  
  <p>The docs say this is because I don't have an id field which isn't true.
  I can fiddle around and try to get it working but I prefer a conventional way as do I need to use <code>saveAssociated</code>? What is the method to save over more than 1 related table?</p>
  
  <p>The User table has a id field and the Teacher table had the user_id foreign key.</p>
  
  <p>Now before I posted I checked <code>saveAll</code>, <code>updateAll</code> and other posts here.</p>
  
  <p>The 1 models are <code>User</code> and <code>Teacher</code>. A <code>User</code> <code>hasOne</code> <code>Teacher</code> and a <code>Teacher</code> <code>belongsTo</code> a <code>User</code>.</p>
  
  <p>I am not sure if <code>saveAll</code> or <code>updateAll</code> is the way to go because it doesn't talk about edits much in the docs but add new.</p>
  
  <p><a href="http://book.cakephp.org/2.0/en/models/saving-your-data.html" rel="nofollow noreferrer">http://book.cakephp.org/2.0/en/models/saving-your-data.html</a></p>
  
  <p><a href="https://stackoverflow.com/questions/21043445/cakephp-updating-multiple-tables-at-the-same-time">CakePHP - Updating multiple tables at the same time</a></p>
  
  <p><strong>View Code</strong>
  </p>
  
  <pre><code>&lt;?php
      echo $this-&gt;Form-&gt;create('User');
      echo $this-&gt;Form-&gt;input('User.username');   //text
      echo $this-&gt;Form-&gt;input('Teacher.firstname');   //text
      echo $this-&gt;Form-&gt;input('Teacher.surname');  
      echo $this-&gt;Form-&gt;input('Teacher.address');   //text
      echo $this-&gt;Form-&gt;input('Teacher.suburb'); 
      echo $this-&gt;Form-&gt;input('Teacher.phone'); 
  echo $this-&gt;Form-&gt;end('Save Post');
  ?&gt;
  </code></pre>
  
  <p><strong>Controller Code</strong></p>
  
  
  
  <pre><code>&lt;?php
  public function editteacher($id = null) {
      if (!$id) {
          throw new NotFoundException(__('Invalid post'));
      }
  
      $post = $this-&gt;User-&gt;findById($id);
      if (!$post) {
          throw new NotFoundException(__('Invalid post'));
      }
  
      if ($this-&gt;request-&gt;is(array('post', 'put'))) {
          $this-&gt;User-&gt;id = $id;
          if ($this-&gt;User-&gt;saveAll($this-&gt;request-&gt;data)) {
              $this-&gt;Session-&gt;setFlash(__('Your techer has been updated.'));
              return $this-&gt;redirect(array('controller' =&gt; 'teachers', 'action' =&gt; 'displayall'));
          }
          $this-&gt;Session-&gt;setFlash(__('Unable to update your post.'));
      }
  
      if (!$this-&gt;request-&gt;data) {
          $this-&gt;request-&gt;data = $post;
      }
  }
  ?&gt;
  </code></pre>