Browse Source

Fix missing InvalidConfigException import

tags/1.6.0
Alban Jubert 6 years ago
parent
commit
86f293bec3
  1. 39
      src/SaveRelationsBehavior.php

39
src/SaveRelationsBehavior.php

@ -8,6 +8,7 @@ use yii\base\Behavior;
use yii\base\Component; use yii\base\Component;
use yii\base\Exception; use yii\base\Exception;
use yii\base\InvalidArgumentException; use yii\base\InvalidArgumentException;
use yii\base\InvalidConfigException;
use yii\base\ModelEvent; use yii\base\ModelEvent;
use yii\base\UnknownPropertyException; use yii\base\UnknownPropertyException;
use yii\db\ActiveQuery; use yii\db\ActiveQuery;
@ -148,6 +149,25 @@ class SaveRelationsBehavior extends Behavior
} }
/** /**
* Set the named single relation with the given value
* @param string $relationName
* @param $value
* @throws \yii\base\InvalidArgumentException
*/
protected function setSingleRelation($relationName, $value)
{
/** @var BaseActiveRecord $owner */
$owner = $this->owner;
/** @var ActiveQuery $relation */
$relation = $owner->getRelation($relationName);
if (!($value instanceof $relation->modelClass)) {
$value = $this->processModelAsArray($value, $relation, $relationName);
}
$this->_newRelationValue[$relationName] = $value;
$owner->populateRelation($relationName, $value);
}
/**
* Set the named multiple relation with the given value * Set the named multiple relation with the given value
* @param string $relationName * @param string $relationName
* @param $value * @param $value
@ -272,25 +292,6 @@ class SaveRelationsBehavior extends Behavior
} }
/** /**
* Set the named single relation with the given value
* @param string $relationName
* @param $value
* @throws \yii\base\InvalidArgumentException
*/
protected function setSingleRelation($relationName, $value)
{
/** @var BaseActiveRecord $owner */
$owner = $this->owner;
/** @var ActiveQuery $relation */
$relation = $owner->getRelation($relationName);
if (!($value instanceof $relation->modelClass)) {
$value = $this->processModelAsArray($value, $relation, $relationName);
}
$this->_newRelationValue[$relationName] = $value;
$owner->populateRelation($relationName, $value);
}
/**
* Before the owner model validation, save related models. * Before the owner model validation, save related models.
* For `hasOne()` relations, set the according foreign keys of the owner model to be able to validate it * For `hasOne()` relations, set the according foreign keys of the owner model to be able to validate it
* @param ModelEvent $event * @param ModelEvent $event

Loading…
Cancel
Save