Skip to content

Commit

Permalink
Enh: Аdjust access to save the relation la-haute-societe#66 checkRela…
Browse files Browse the repository at this point in the history
…tionsSafe
  • Loading branch information
sokollondon committed Feb 10, 2021
1 parent cc6b35d commit d0c588a
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/SaveRelationsBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ class SaveRelationsBehavior extends Behavior

public $relations = [];
public $relationKeyName = self::RELATION_KEY_FORM_NAME;
/**
* Save only safe relation. Check as attribute.
* @see https://www.yiiframework.com/doc/guide/2.0/en/input-validation
* @var bool
*/
public $checkRelationsSafe = false;

private $_relations = [];
private $_oldRelationValue = []; // Store initial relations value
Expand Down Expand Up @@ -729,6 +735,7 @@ public function loadRelations($data)
/** @var BaseActiveRecord $owner */
$owner = $this->owner;
foreach ($this->_relations as $relationName) {
if($this->checkRelationsSafe && !$owner->isAttributeSafe($relationName)) continue;
$keyName = $this->_getRelationKeyName($relationName);
if (array_key_exists($keyName, $data)) {
$owner->{$relationName} = $data[$keyName];
Expand Down

0 comments on commit d0c588a

Please sign in to comment.