Answer the question
In order to leave comments, you need to log in
How to combine AR with DAO in Yii2?
How to combine AR with DAO in Yii2?
Using ActiveRecord, I want to apply transactions that can only be done with DAO.
I learned what can be done, I don’t know how to do it.
Tell me how to register in the config and in the controller, so as not to hook AR.
Answer the question
In order to leave comments, you need to log in
I think this should help
https://github.com/yiisoft/yii2/blob/master/docs/g...
$db = Post::getDb();
$db->transaction(function($db) {
$db->createCommand($sql1)->execute();
$db->createCommand($sql2)->execute();
// ... executing other SQL statements ...
});
If you want to use transactions when saving the model, then you need to override the transaction method in the model class
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question