What I want to achieve here is to make sure that if one of the query fails to roll back the other as well. So either both or none! The above scheme does not work. I tested it by braking second query and I still end up with the first query executed successfully and the second failed.
Please point me to what I’ve gotten wrong or a better way of achieving this.
By the way, I think you have an error in the order of the sentences.
From the guide:
$model=Post::model();
$transaction=$model->dbConnection->beginTransaction();
try
{
// find and save are two steps which may be intervened by another request
// we therefore use a transaction to ensure consistency and integrity
$post=$model->findByPk(10);
$post->title='new post title';
$post->save();
$transaction->commit();
}
catch(Exception $e)
{
$transaction->rollBack();
}
However, converting my AR query to DAO one so having 3 DAO queries did it. I wonder why transactions don’t work for AR? Should an enhancement be raised? Your thoughts?
the updateCounters() AR query is sooo comfortable and I don’t want to swap with for couple of DAO queries.
I’d bet that AR-only would work too. Perhaps there is a hidden (partial) db close/reopen that leads to an autocommit? Just guessing, though. At least - several Yii versions back - I had to toggle the db->active property when mixing AR with DAO.
Shit hit fan and came back! Even though I was able to move the transaction thing that autoCommit totally messed up my other queries where I am updating stuff. I have declared the autoCommit=false in config/main.php db secion Is this not the way to declare autoCommit value? when I remove the autoCommit all works well.