Skip to content

Commit d20c349

Browse files
committed
Fix ParamNameMismatch issue
Closes #96
1 parent b8fff65 commit d20c349

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## [Unreleased]
88

9-
* Nothing
9+
### Fixed
10+
11+
* Fix ParamNameMismatch issue [#96](https://github.com/swisnl/json-api-client/issues/96).
1012

1113
## [2.0.1] - 2022-02-08
1214

src/Concerns/HasRelations.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,29 +175,29 @@ public function getRelationValue(string $name): ?DataInterface
175175
/**
176176
* Set the specific relationship on the model.
177177
*
178-
* @param string $name
179-
* @param \Swis\JsonApi\Client\Interfaces\DataInterface|false|null $data
178+
* @param string $relation
179+
* @param \Swis\JsonApi\Client\Interfaces\DataInterface|false|null $value
180180
* @param \Swis\JsonApi\Client\Links|null $links
181181
* @param \Swis\JsonApi\Client\Meta|null $meta
182182
*
183183
* @return static
184184
*/
185-
public function setRelation(string $name, $data = false, Links $links = null, Meta $meta = null)
185+
public function setRelation(string $relation, $value = false, Links $links = null, Meta $meta = null)
186186
{
187-
$method = Util::stringCamel($name);
187+
$method = Util::stringCamel($relation);
188188
if (method_exists($this, $method)) {
189189
/** @var \Swis\JsonApi\Client\Interfaces\OneRelationInterface|\Swis\JsonApi\Client\Interfaces\ManyRelationInterface $relationObject */
190190
$relationObject = $this->$method();
191-
} elseif ($data instanceof Collection) {
192-
$relationObject = $this->morphToMany($name);
191+
} elseif ($value instanceof Collection) {
192+
$relationObject = $this->morphToMany($relation);
193193
} else {
194-
$relationObject = $this->morphTo($name);
194+
$relationObject = $this->morphTo($relation);
195195
}
196196

197-
if ($data !== false) {
197+
if ($value !== false) {
198198
$relationObject->dissociate();
199-
if ($data !== null) {
200-
$relationObject->associate($data);
199+
if ($value !== null) {
200+
$relationObject->associate($value);
201201
}
202202
}
203203
$relationObject->setLinks($links);

0 commit comments

Comments
 (0)