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. 11
      src/SaveRelationsBehavior.php

11
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();
}

Loading…
Cancel
Save