Transaction across models


Is there a way to use the same transaction across models?

The example in the docs work for one model but I’d love to use a transaction across models.

The alternative seems to be plain SQL but I was wondering if it exists without raw SQL.

Thanks a lot

[color="#C0C0C0"]i making the MultilingualBehavior, and then finish, i will release to the


[color="#FF0000"]it’s my mistake, sorry! [/color]


look up as:


I’m confused.

Is your extension related to transaction? Multilingualbehavior is a bit misleading as far as wording.

The transactions will always cover multiple models until you commit the transaction. I’m not sure how you are starting them, but you can do something like this and it should work over multiple models:

// Start the transaction

$transaction = Yii::app()->db->beginTransaction();

try {

    // Do the updates



    // Commit the transaction



// Was there an error?

catch (Exception $e) {

    // Error, rollback transaction



Is that what you are trying to do?

Yes! Thank you so much.

Is it OK to specify one particular model? Will the transaction still check all models before committing?

That is…

Does it matter if you do:

$transaction = Yii::app()->db->beginTransaction();


$model = new MyModel;

$transaction = $model->dbConnection->beginTransaction();

However you do it… in the end its the current connection object (CDbConnection) that begins the transaction