diff --git a/src/SaveRelationsBehavior.php b/src/SaveRelationsBehavior.php index 950fa62..6df06bb 100644 --- a/src/SaveRelationsBehavior.php +++ b/src/SaveRelationsBehavior.php @@ -261,9 +261,14 @@ class SaveRelationsBehavior extends Behavior */ protected function saveRelatedRecords(BaseActiveRecord $model, ModelEvent $event) { - if (($model->isNewRecord && $model->isTransactional($model::OP_INSERT)) - || (!$model->isNewRecord && $model->isTransactional($model::OP_UPDATE)) - || $model->isTransactional($model::OP_ALL) + if ( + method_exists($model, 'isTransactional') + && is_null($model->getDb()->transaction) + && ( + ($model->isNewRecord && $model->isTransactional($model::OP_INSERT)) + || (!$model->isNewRecord && $model->isTransactional($model::OP_UPDATE)) + || $model->isTransactional($model::OP_ALL) + ) ) { $this->_transaction = $model->getDb()->beginTransaction(); }