Hi
I'm trying to understand your transaction model within ORM context. Let's assume the following pseudo-code example:
$trx = new Phalcon\Mvc\Model\Transaction\Manager();
$handle = $trx->get();
try {
$model1 = new Model1();
$model1->email = $email;
if($model1->save()===false) {
// HOW DO I DETECT DUPLICATE KEY ?
if($reason == 'dupe') {
$handle->rollback();
throw new DupeException();
} else {
throw new DBException();
}
}
} catch(DupeException $e) {
// FALLBACK
$model1::findFirst(array('email' => $email));
}
$model2 = new Model2();
$model2->model1_id = $model1->id;
$model2->save();
$handle->commit();
-
How do I specifically extract the "save" failure reason ?
-
Is there a way to execute $model1::findFirst within the same trasaction ?
- Why have not you used the standard patter of:
begin
try
query1
query2
queryn
commit
catch Exception
rollback
I find it so much more elegant and flexible than the if($model1->save() === false)
Thanks in advance....