Hi All,
I have one doubt about the transactions. When I have this piece of code, the connection of the model uses the same transaction? All commands are executed inside of the same connection?
try
{
$transaction = Yii::app()->db->beginTransaction();
$item = Item::model()->findByPk(‘1’);
$item->Name = Xpto;
if(!$item->Save())
throw new CDbException('Errorrrr');
$sql = ‘INSERT INTO ItemHistoric (ItemId, Stock) SELECT ItemId, Stock FROM Item WHERE 1 = 1’;
$command = Yii::app()->db->createCommand($sql);
$rowCount = $command->execute();
$transaction->commit();
}
catch (Exception $e) {
$transaction->rollback();
}
ps: Please note this just very, very dummy sample. It’s just to exemplify.
Thanks