title: CakePHP 2.3.x database transaction
body: <p>I need your help using transactions in CakePHP. </p>
  
  <p>I have a Product model, with clause hasMany to Price and Property models (key product_id).</p>
  
  <p>In my Product model, I add </p>
  
  <pre><code>function begin() {
      $db =&amp; ConnectionManager::getDataSource($this-&gt;useDbConfig);
      $db-&gt;begin($this); 
  } 
  
  function commit() {
      $db =&amp; ConnectionManager::getDataSource($this-&gt;useDbConfig);
      $db-&gt;commit($this); 
  } 
  function rollback() 
  {
      $db =&amp; ConnectionManager::getDataSource($this-&gt;useDbConfig);
      $db-&gt;rollback($this); 
  }
  </code></pre>
  
  <p>And in ProductController I use save() to save my Product, and then my Price and Property. (I use only save(), not saveAll() ).</p>
  
  <p>My code is:</p>
  
  <pre><code>$this-&gt;Product-&gt;begin(); 
  $error = false; 
  if($this-&gt;Product-&gt;save($data) 
  { 
      //my functions and calculations 
      if(!$this-&gt;Price-&gt;save($data_one) 
      { 
          $error = true; 
      }
      //calculations
      if(!$this&gt;Property-&gt;save($my_data)
      { 
          $error = true; 
      }
  } 
  if($error) {
      $this-&gt;Product-&gt;rollback();
  }
  else
  {
      $this-&gt;Product-&gt;commit(); 
  }
  </code></pre>
  
  <p>The problem is that if I have an error inside the save Price or Property row, the Product is still added. I would have thought that when I have any errors, none of my rows would be added (i.e. a rollback would delete it).</p>
  
  <p>I am using CakePHP 2.3.8</p>