Reputation: 1029
Is there any possible way to define a transaction for active record methods? I have Two activeRecords named as Answer and QuizMark which have tow method.I want say server to execute them as a trasaction. here is my code :
public function actionChangeAnswersStatus($formId, $userId) {
if (isset($formId) && isset($userId)) {
Answer::changeIgnoreStatus($formId, $userId);
QuizMark::changeIgnoreStatus($formId, $userId);
echo 'quizes';
}
}
is there any possible solution?
Upvotes: 0
Views: 55
Reputation: 2985
Try:
$connection = $this->connectDb();
$transaction = $connection->beginTransaction();
// You commands
$transaction->commit();
// Note: if an error occurs, call rollBack...
$transaction->rollBack();
Upvotes: 1