Skip to content

Commit 7fa371c

Browse files
authored
Merge pull request #66 from tuyakhov/allow_deleting_resources
make allowDeletingResources invisible in responses, improve autoload …
2 parents 30f9f94 + 4338ee8 commit 7fa371c

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

composer.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@
2424
},
2525
"autoload": {
2626
"psr-4": {
27-
"tuyakhov\\jsonapi\\": "src/",
27+
"tuyakhov\\jsonapi\\": "src/"
28+
}
29+
},
30+
"autoload-dev": {
31+
"psr-4": {
2832
"tuyakhov\\jsonapi\\tests\\": "tests/"
2933
}
3034
}

src/ResourceTrait.php

+17-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ trait ResourceTrait
1616
* @var bool a flag that enables/disables deleting of the model that contains the foreign key when setting relationships
1717
* By default the model's foreign key will be set `null` and saved.
1818
*/
19-
public $allowDeletingResources = false;
19+
protected $allowDeletingResources = false;
2020

2121
/**
2222
* @return string
@@ -145,4 +145,20 @@ protected function resolveFields(array $fields, array $fieldSet = [])
145145

146146
return $result;
147147
}
148+
149+
/**
150+
* @param $value boolean
151+
*/
152+
public function setAllowDeletingResources($value)
153+
{
154+
$this->allowDeletingResources = $value;
155+
}
156+
157+
/**
158+
* @return bool
159+
*/
160+
public function getAllowDeletingResources()
161+
{
162+
return $this->allowDeletingResources;
163+
}
148164
}

src/actions/Action.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ protected function linkRelationships($model, array $data = [])
6767
$records = $relatedClass::find()->andWhere(['in', $relatedClass::primaryKey(), $ids])->all();
6868

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

7474
$model->setResourceRelationship($name, $records);

0 commit comments

Comments
 (0)