Browse Source

Fix for transaction being triggered multiple times for nested relations and detection of the transaction support for the ActiveRecord being used

tags/1.4.0
Alban Jubert 7 years ago
parent
commit
3409c652b3
  1. 7
      src/SaveRelationsBehavior.php

7
src/SaveRelationsBehavior.php

@ -261,9 +261,14 @@ class SaveRelationsBehavior extends Behavior
*/ */
protected function saveRelatedRecords(BaseActiveRecord $model, ModelEvent $event) protected function saveRelatedRecords(BaseActiveRecord $model, ModelEvent $event)
{ {
if (($model->isNewRecord && $model->isTransactional($model::OP_INSERT)) 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->isNewRecord && $model->isTransactional($model::OP_UPDATE))
|| $model->isTransactional($model::OP_ALL) || $model->isTransactional($model::OP_ALL)
)
) { ) {
$this->_transaction = $model->getDb()->beginTransaction(); $this->_transaction = $model->getDb()->beginTransaction();
} }

Loading…
Cancel
Save