|
|
@ -217,9 +217,7 @@ class SaveRelationsBehavior extends Behavior |
|
|
|
if (empty($fks)) { |
|
|
|
if (empty($fks)) { |
|
|
|
// Get the right link definition |
|
|
|
// Get the right link definition |
|
|
|
if ($relation->via instanceof BaseActiveRecord) { |
|
|
|
if ($relation->via instanceof BaseActiveRecord) { |
|
|
|
/** @var BaseActiveRecord|array $viaQuery */ |
|
|
|
$link = $relation->via->link; |
|
|
|
$viaQuery = $relation->via; |
|
|
|
|
|
|
|
$link = $viaQuery->link; |
|
|
|
|
|
|
|
} elseif (is_array($relation->via)) { |
|
|
|
} elseif (is_array($relation->via)) { |
|
|
|
list($viaName, $viaQuery) = $relation->via; |
|
|
|
list($viaName, $viaQuery) = $relation->via; |
|
|
|
$link = $viaQuery->link; |
|
|
|
$link = $viaQuery->link; |
|
|
@ -295,17 +293,7 @@ class SaveRelationsBehavior extends Behavior |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected function saveRelatedRecords(BaseActiveRecord $model, ModelEvent $event) |
|
|
|
protected function saveRelatedRecords(BaseActiveRecord $model, ModelEvent $event) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if ( |
|
|
|
$this->startTransactionForModel($model); |
|
|
|
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(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
foreach ($this->_relations as $relationName) { |
|
|
|
foreach ($this->_relations as $relationName) { |
|
|
|
if (array_key_exists($relationName, $this->_oldRelationValue)) { // Relation was not set, do nothing... |
|
|
|
if (array_key_exists($relationName, $this->_oldRelationValue)) { // Relation was not set, do nothing... |
|
|
@ -636,4 +624,22 @@ class SaveRelationsBehavior extends Behavior |
|
|
|
$this->validateRelationModel($pettyRelationName, $relationName, $relationModel); |
|
|
|
$this->validateRelationModel($pettyRelationName, $relationName, $relationModel); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* @param BaseActiveRecord $model |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected function startTransactionForModel(BaseActiveRecord $model) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
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(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|