title: CakePHP Save newly created ID in Parent ID field of self assoc model
body: <p>I have a parent/child self association table where when the id = parent_id, that id is it's own parent. However I'm having trouble saving data into my table from the add action/view</p>
  
  <p>From add.ctp view - when adding a new record, I select a parent_id from the drop down box and enter a name. </p>
  
  <pre><code>&lt;?php
      echo $this-&gt;Form-&gt;input('parent_id', array('empty' =&gt; 'No Parent'));
      echo $this-&gt;Form-&gt;input('name');
  ?&gt;
  </code></pre>
  
  <p>If user selects "No Parent" this means I would like the parent_id = id where id is the unique ID automatically created in DB at time it is saved. </p>
  
  <p>This is what is passed into $this->request->data when 'No Parent' is selected.</p>
  
  <pre><code>array(
      'Item' =&gt; array(
          'parent_id' =&gt; '',
          'name' =&gt; 'testname'
      )
  )
  </code></pre>
  
  <p>I have tried to set the parent_id = id in the beforeSave but since id does not yet exist, there is nothing to assign parent_id to. I have also tried calling the "parent" model save first and saveAll in the controller but those don't work either.</p>
  
  <p>Controller</p>
  
  <pre><code>public function add() {
      if ($this-&gt;request-&gt;is('post')) {
          $this-&gt;Item-&gt;create();
  
          //have tried calling parent model in self association first but 
          //if ($this-&gt;Item-&gt;ParentItem-&gt;save($this-&gt;request-&gt;data)) {
          if ($this-&gt;Item-&gt;saveAll($this-&gt;request-&gt;data)) {
  
              $this-&gt;Session-&gt;setFlash(__('The item has been saved'));
              $this-&gt;redirect(array('action' =&gt; 'index'));
          } else {
              $this-&gt;Session-&gt;setFlash(__('The item could not be saved. Please, try again.'));
          }
      }
  </code></pre>
  
  <p>Item.php / Model relationship</p>
  
  <pre><code>public $belongsTo = array(
    'ParentItem' =&gt; array(
    'className' =&gt; 'Item',
    'foreignKey' =&gt; 'parent_id',
    'conditions' =&gt; '',
    'fields' =&gt; '',
    'order' =&gt; ''
    )
  );
  
  public $hasMany = array(
    'ChildItem' =&gt; array(
    'className' =&gt; 'Item',
    'foreignKey' =&gt; 'parent_id',
    'dependent' =&gt; false,
    'conditions' =&gt; '',
    'fields' =&gt; '',
    'order' =&gt; '',
    ) 
  );
  </code></pre>
  
  <p>How can I take an ID that is just created/saved and save that to another field, in this case parent_id?</p>
  
  <p>UPDATE:
  I have been working on this some more and I have used getInsertId() to get the last inserted Id and I am trying to save that into the parent_id, but there is something that prevents this. I have removed all model validation to make sure it wasn't that. But is there something in Cake (or my association setup) that does not allow parent_id = id (i.e. a row is it's own parent?</p>
  
  <p>This is the latest code in my add action... This saves a row to the DB, but w/o a parent_id. I then try to edit using the add action and set the parent_id = id, but even the edit wont allow a save.</p>
  
  <pre><code>public function add() {
      if ($this-&gt;request-&gt;is('post')) {
          $this-&gt;Item-&gt;create();
          if ($this-&gt;Item-&gt;save($this-&gt;request-&gt;data)) {
              $last_id = $this-&gt;Item-&gt;getInsertId();
              $this-&gt;Item-&gt;saveField('parent_id', $last_id);
              $this-&gt;Session-&gt;setFlash(__('The item has been saved'));
              $this-&gt;redirect(array('action' =&gt; 'index'));
          } else {
              $this-&gt;Session-&gt;setFlash(__('The item could not be saved. Please, try again.'));
          }
      }
  </code></pre>
  
  <p>I have also tried calling $this->Item->ParentItem->save(), saveAll, 'deep' => true, but still nothing is allowing me to update the parent_id column. A row ge</p>
  
  <p>Thanks in advance</p>