diff --git a/README.md b/README.md index c5462ef..dd61480 100644 --- a/README.md +++ b/README.md @@ -281,5 +281,5 @@ In that case, a call to the `load()` method will also automatically trigger a ca The `relationKeyName` property can be used to decide how the relations data will be retrieved from the data parameter. Possible constants values are: -* `SaveRelationsBehavior::RELATION_KEY_FORMNAME` (default): the key name will be compute using the model [`formName()`](https://www.yiiframework.com/doc/api/2.0/yii-base-model#formName()-detail) method -* `SaveRelationsBehavior::RELATION_KEY_MODELNAME`: the relation name as defined in the behavior declarations will be used +* `SaveRelationsBehavior::RELATION_KEY_FORM_NAME` (default): the key name will be compute using the model [`formName()`](https://www.yiiframework.com/doc/api/2.0/yii-base-model#formName()-detail) method +* `SaveRelationsBehavior::RELATION_KEY_RELATION_NAME`: the relation name as defined in the behavior declarations will be used diff --git a/src/SaveRelationsBehavior.php b/src/SaveRelationsBehavior.php index 75ed45b..19374db 100644 --- a/src/SaveRelationsBehavior.php +++ b/src/SaveRelationsBehavior.php @@ -27,11 +27,11 @@ use yii\helpers\VarDumper; class SaveRelationsBehavior extends Behavior { - const RELATION_KEY_FORMNAME = 'formName'; - const RELATION_KEY_MODELNAME = 'modelName'; + const RELATION_KEY_FORM_NAME = 'formName'; + const RELATION_KEY_RELATION_NAME = 'relationName'; public $relations = []; - public $relationKeyName = self::RELATION_KEY_FORMNAME; + public $relationKeyName = self::RELATION_KEY_FORM_NAME; private $_relations = []; private $_oldRelationValue = []; // Store initial relations value @@ -776,10 +776,10 @@ class SaveRelationsBehavior extends Behavior private function _getRelationKeyName($relationName) { switch ($this->relationKeyName) { - case self::RELATION_KEY_MODELNAME: + case self::RELATION_KEY_RELATION_NAME: $keyName = $relationName; break; - case self::RELATION_KEY_FORMNAME: + case self::RELATION_KEY_FORM_NAME: /** @var BaseActiveRecord $owner */ $owner = $this->owner; /** @var ActiveQuery $relation */ diff --git a/tests/SaveRelationsBehaviorTest.php b/tests/SaveRelationsBehaviorTest.php index 099e5f7..d62450e 100644 --- a/tests/SaveRelationsBehaviorTest.php +++ b/tests/SaveRelationsBehaviorTest.php @@ -852,7 +852,7 @@ class SaveRelationsBehaviorTest extends \PHPUnit_Framework_TestCase $company->attachBehavior('saveRelations', [ 'class' => SaveRelationsBehavior::className(), 'relations' => ['users'], - 'relationKeyName' => SaveRelationsBehavior::RELATION_KEY_MODELNAME + 'relationKeyName' => SaveRelationsBehavior::RELATION_KEY_RELATION_NAME ]); $data = [