Skip to content

Commit

Permalink
Merge pull request #66 from tuyakhov/allow_deleting_resources
Browse files Browse the repository at this point in the history
make allowDeletingResources invisible in responses, improve autoload …
  • Loading branch information
tuyakhov committed Jun 21, 2020
2 parents 30f9f94 + 4338ee8 commit 7fa371c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
6 changes: 5 additions & 1 deletion composer.json
Expand Up @@ -24,7 +24,11 @@
},
"autoload": {
"psr-4": {
"tuyakhov\\jsonapi\\": "src/",
"tuyakhov\\jsonapi\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"tuyakhov\\jsonapi\\tests\\": "tests/"
}
}
Expand Down
18 changes: 17 additions & 1 deletion src/ResourceTrait.php
Expand Up @@ -16,7 +16,7 @@ trait ResourceTrait
* @var bool a flag that enables/disables deleting of the model that contains the foreign key when setting relationships
* By default the model's foreign key will be set `null` and saved.
*/
public $allowDeletingResources = false;
protected $allowDeletingResources = false;

/**
* @return string
Expand Down Expand Up @@ -145,4 +145,20 @@ protected function resolveFields(array $fields, array $fieldSet = [])

return $result;
}

/**
* @param $value boolean
*/
public function setAllowDeletingResources($value)
{
$this->allowDeletingResources = $value;
}

/**
* @return bool
*/
public function getAllowDeletingResources()
{
return $this->allowDeletingResources;
}
}
4 changes: 2 additions & 2 deletions src/actions/Action.php
Expand Up @@ -67,8 +67,8 @@ protected function linkRelationships($model, array $data = [])
$records = $relatedClass::find()->andWhere(['in', $relatedClass::primaryKey(), $ids])->all();

/** @see ResourceTrait::$allowDeletingResources */
if (property_exists($model, 'allowDeletingResources')) {
$model->allowDeletingResources = $this->enableResourceDeleting;
if (method_exists($model, 'setAllowDeletingResources')) {
$model->setAllowDeletingResources($this->enableResourceDeleting);
}

$model->setResourceRelationship($name, $records);
Expand Down

0 comments on commit 7fa371c

Please sign in to comment.