|
|
|
@ -337,7 +337,7 @@ class SaveRelationsBehavior extends Behavior
|
|
|
|
|
*/ |
|
|
|
|
protected function saveModelRecord(BaseActiveRecord $model, ModelEvent $event, $pettyRelationName, $relationName) |
|
|
|
|
{ |
|
|
|
|
$this->validateRelationModel($pettyRelationName, $relationName, $model, $event); |
|
|
|
|
$this->validateRelationModel($pettyRelationName, $relationName, $model); |
|
|
|
|
if ($event->isValid && (count($model->dirtyAttributes) || $model->isNewRecord)) { |
|
|
|
|
Yii::debug("Saving {$pettyRelationName} relation model", __METHOD__); |
|
|
|
|
$model->save(false); |
|
|
|
@ -523,7 +523,6 @@ class SaveRelationsBehavior extends Behavior
|
|
|
|
|
$owner = $this->owner; |
|
|
|
|
$relation = $owner->getRelation($relationName); |
|
|
|
|
|
|
|
|
|
if ($this->_hasActiveRelationTrait($relation)) { |
|
|
|
|
// Process new relations |
|
|
|
|
$existingRecords = []; |
|
|
|
|
/** @var ActiveQuery $relationModel */ |
|
|
|
@ -583,7 +582,6 @@ class SaveRelationsBehavior extends Behavior
|
|
|
|
|
$owner->link($relationName, $actualModels[$key], $junctionTableColumns); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @param $relationName |
|
|
|
@ -591,9 +589,7 @@ class SaveRelationsBehavior extends Behavior
|
|
|
|
|
private function _afterSaveHasOneRelation($relationName) |
|
|
|
|
{ |
|
|
|
|
$owner = $this->owner; |
|
|
|
|
$relation = $owner->getRelation($relationName); |
|
|
|
|
|
|
|
|
|
if ($this->_hasActiveRelationTrait($relation)) { |
|
|
|
|
if ($this->_oldRelationValue[$relationName] !== $owner->{$relationName}) { |
|
|
|
|
if ($owner->{$relationName} instanceof BaseActiveRecord) { |
|
|
|
|
$owner->link($relationName, $owner->{$relationName}); |
|
|
|
@ -607,15 +603,4 @@ class SaveRelationsBehavior extends Behavior
|
|
|
|
|
$owner->{$relationName}->save(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @param ActiveQuery $relation |
|
|
|
|
* @return bool |
|
|
|
|
*/ |
|
|
|
|
private function _hasActiveRelationTrait(ActiveQuery $relation) |
|
|
|
|
{ |
|
|
|
|
$relationTraits = class_uses($relation); |
|
|
|
|
return in_array('yii\db\ActiveRelationTrait', $relationTraits); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|