Here you are opening one connection with one model then save another object, yii will open another connection for another object so connections are different and they can not be in the same transaction. DO you know how to save model object using the same transaction? Or I am wrong with 1st statement.
$transaction=$model->dbConnection->beginTransaction();
try
{
$model->save();
$model_b->save();
$model_c->delete();
throw new Exception('Error !!'); // add to check if rollback will happen
$transaction->commit();
}
catch (Exception $e)
{
$transaction->rollback();
}
If you haven’t overridden getDbConnection() method in a CActiveRecord derived class, it will use ‘db’ application component as the database connection for it by default.
In fact, "Yii::app()->db" equals "$model->dbConnection" in most of the case.
CActiveRecord::getDbConnection() method
The very first instance of AR will actually open the db connection through Yii::app()->db, but once the app component has opened the connection, it will be shared by other instances of AR, not only of the same model but of all the AR models.
If the db connection should have been opened and closed every time a single AR object is created and saved, then transaction would be virtually impossible … but fortunately it’s not the case.