title: How do I run transactions in CakePHP3 for multiple model operation?
body: <p>I want to use transactions on multiple insert/update query for multiple model/table.</p>
  
  <p>In <a href="http://book.cakephp.org/3.0/en/orm/database-basics.html#using-transactions" rel="nofollow">cakephp3 documentation</a>  have an example of transaction using <strong>connection manager</strong> <code>execute()</code> method but I have to use transaction with <code>save()</code> method of cakephp3. I tried it using <code>save()</code> method but it didn't work. There was a SQL error, it execute all query and saving data except the query where the sql error have, rollback didn't work!</p>
  
  <p>my code was like-</p>
  
  <pre><code>$connection = ConnectionManager::get('default');
  
  $connection-&gt;transactional(function ($connection) use($inputs, $status) {
    $serviceTbl = $this-&gt;Service;
    $service = $serviceTbl-&gt;newEntity();
    $service-&gt;name = $inputs['name'];
    $service = $serviceTbl-&gt;save($service);
  if($service)
   {
     $this-&gt;loadModel('SrvApiClientInfo');
     $SrvApiClientInfo = $this-&gt;SrvApiClientInfo;
     $SrvApiClient = $SrvApiClientInfo-&gt;newEntity();
     $SrvApiClient-&gt;client_name = $inputs['basic_info']['client_name'];
     $SrvApiClient-&gt;organization_name = $inputs['basic_info']['vendor_name'];
     $SrvApiClient-&gt;address = $inputs['basic_info']['address'];
     $SrvApiClient-&gt;email = $inputs['basic_info']['email'];
     $SrvApiClient-&gt;mobile = $inputs['basic_info']['mobile'];
     $SrvApiClient-&gt;phone = $inputs['basic_info']['phone'];
     $SrvApiClient-&gt;fax = $inputs['basic_info']['fax'];
     $SrvApiClient-&gt;emergency_contact_name = $inputs['basic_info']['emergency_contact_name'];
     $SrvApiClient-&gt;emergency_contact_mobile = $inputs['basic_info']['emergency_contact_mobile'];
     $SrvApiClient-&gt;emergency_contact_designation = $inputs['basic_info']['emergency_contact_designation'];
     $SrvApiClient = $SrvApiClientInfo-&gt;save($SrvApiClient);
        if($SrvApiClient){
             $this-&gt;loadModel('ServiceApiRegistration');
             $tblServiceApiRegistration = $this-&gt;ServiceApiRegistration;
                foreach($inputs['method'] as $method)
                {
                $ServiceApiRegistration = $tblServiceApiRegistration-&gt;newEntity();
                $ServiceApiRegistration-&gt;service_id = $service['service_id'];
                $ServiceApiRegistration-&gt;service_api_id = $method;
                $ServiceApiRegistration-&gt;client_id = $SrvApiClient['client_id'];
                $ServiceApiRegistration-&gt;status_id = $status['Inactive'];
                $tblServiceApiRegistration-&gt;save($ServiceApiRegistration);
                }
           }
       }
      });
  </code></pre>