I have two table, BrokerInfo and BrokerBank in my database. If data is saved in BrokerInfo then it will start the process to save data in BrokerBank table. If it is failed to save data in table 2 then it should remove data from table 1 in database. I am facing problem to remove data from table1 in database, how can i do it? Here is my code for add action :
public function add() {
if ($this->request->is('post'))
{
$this->BrokerInfo->create();
$this->BrokerInfo->save($this->request->data);
$id=$this->BrokerInfo->getLastInsertId();
$this->BrokerBank->begin();
$this->BrokerBank->create();
$this->request->data['BrokerBank']['broker_info_id'] = $id;
if($this->BrokerBank->save($this->request->data))
{
$this->BrokerInfo->commit();
$this->redirect(array('action' => 'index'));
}
else
{
$this->BrokerInfo->rollback();
$this->Session->setFlash(__('The information could not be saved. Please, try again.'));
}
}
}