Skip to content
This repository has been archived by the owner on Jul 1, 2022. It is now read-only.

Removed unnecessary double validation #55

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/SaveRelationsBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ private function _prepareHasOneRelation(BaseActiveRecord $model, $relationName,
// Save Has one relation new record
if ($event->isValid && (count($model->dirtyAttributes) || $model->{$relationName}->isNewRecord)) {
Yii::debug('Saving ' . self::prettyRelationName($relationName) . ' relation model', __METHOD__);
if ($model->{$relationName}->save()) {
if ($model->{$relationName}->save(false)) {
$this->_savedHasOneModels[] = $model->{$relationName};
}
}
Expand Down Expand Up @@ -462,7 +462,7 @@ protected function _setRelationForeignKeys($relationName)
foreach ($relation->link as $relatedAttribute => $modelAttribute) {
if ($owner->{$modelAttribute} !== $owner->{$relationName}->{$relatedAttribute}) {
if ($owner->{$relationName}->isNewRecord) {
$owner->{$relationName}->save();
$owner->{$relationName}->save(false);
}
$owner->{$modelAttribute} = $owner->{$relationName}->{$relatedAttribute};
}
Expand Down Expand Up @@ -532,7 +532,7 @@ public function _afterSaveHasManyRelation($relationName)
if ($relationModel->isNewRecord) {
if (!empty($relation->via)) {
if ($relationModel->validate()) {
$relationModel->save();
$relationModel->save(false);
} else {
$this->_addError($relationModel, $owner, $relationName, self::prettyRelationName($relationName, $i));
throw new DbException('Related record ' . self::prettyRelationName($relationName, $i) . ' could not be saved.');
Expand All @@ -545,7 +545,7 @@ public function _afterSaveHasManyRelation($relationName)
}
if (count($relationModel->dirtyAttributes)) {
if ($relationModel->validate()) {
$relationModel->save();
$relationModel->save(false);
} else {
$this->_addError($relationModel, $owner, $relationName, self::prettyRelationName($relationName));
throw new DbException('Related record ' . self::prettyRelationName($relationName) . ' could not be saved.');
Expand Down Expand Up @@ -655,7 +655,7 @@ private function _afterSaveHasOneRelation($relationName)
}
}
if ($owner->{$relationName} instanceof BaseActiveRecord) {
$owner->{$relationName}->save();
$owner->{$relationName}->save(false);
}
}

Expand Down Expand Up @@ -706,7 +706,7 @@ public function afterDelete()
* @param array $data
* @throws InvalidConfigException
*/
public function loadRelations($data)
public function loadRelationsFromData($data)
{
/** @var BaseActiveRecord $owner */
$owner = $this->owner;
Expand Down
6 changes: 3 additions & 3 deletions src/SaveRelationsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ trait SaveRelationsTrait
public function load($data, $formName = null)
{
$loaded = parent::load($data, $formName);
if ($loaded && $this->hasMethod('loadRelations')) {
$this->loadRelations($data);
if ($loaded && $this->hasMethod('loadRelationsFromData')) {
$this->loadRelationsFromData($data);
}
return $loaded;
}
}
}