Welcome Guest, Not a member yet? Register   Sign In
Transactions with Model
#9

(11-27-2022, 01:37 AM)RedWd Wrote: I found a solution. The code below:

Code:
$UserModel->db->transStart();

$UserModel->save($user);
$ProfileModel->save($profile);

$UserModel->db->transComplete();

Turn into:

Code:
$this->db->transBegin();

if (! $UserModel->save($user)){
$failed = true;
}

if (! $ProfileModel->save($user)){
$failed = true;
}if ($this->db->transStatus() === false || $failed) {
    $this->db->transRollback();
} else {
    $this->db->transCommit();
}


That's all. Enjoy

$this->db, $userModel and $profilModel are using a same connection?
Reply


Messages In This Thread
Transactions with Model - by RedWd - 11-19-2022, 07:43 AM
RE: Transactions with Model - by InsiteFX - 11-19-2022, 11:49 PM
RE: Transactions with Model - by RedWd - 11-23-2022, 06:29 PM
RE: Transactions with Model - by kenjis - 11-23-2022, 10:40 PM
RE: Transactions with Model - by RedWd - 11-24-2022, 02:57 AM
RE: Transactions with Model - by kenjis - 11-25-2022, 02:40 PM
RE: Transactions with Model - by kenjis - 11-25-2022, 11:18 PM
SOLVED Transactions with Model - by RedWd - 11-27-2022, 01:37 AM
RE: SOLVED Transactions with Model - by nfaiz - 11-27-2022, 08:05 AM



Theme © iAndrew 2016 - Forum software by © MyBB