A
A
Artyom2015-09-06 14:26:14
Yii
Artyom, 2015-09-06 14:26:14

How to work with transactions in yii2?

How to make a transaction with two tables? In this case, you first need to save to one table, then take the ID and save to another table.
This is the code that doesn't work:

Test1::getDb()->transaction(function($db) use ($model2, $model2)  {
           Test2::getDb()->transaction(function($db) use ($model, $model2)  {
                    $model->save();
                    $model2->save();
           });
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Makarov, 2015-09-08
@SamDark

Start one transaction.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question