Skip to content

Commit 1c3d5b3

Browse files
author
Shashank Jain
committed
Fix: hasone and hasMany in nested relation bug
1 parent bbd51e2 commit 1c3d5b3

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

src/RequestParser.php

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -437,20 +437,25 @@ private function parseFields($fields)
437437

438438
$parent = implode(".", $fieldParts);
439439

440-
// The parent might already been set because we cannot rely on order
441-
// in which user sends relations in request
442-
if (!isset($this->relations[$parent])) {
443-
$this->relations[$parent] = [
444-
"limit" => config("api.defaultLimit"),
445-
"offset" => 0,
446-
"order" => "chronological",
447-
"fields" => isset($singular) ? [$singular] : [] ,
448-
"userSpecifiedFields" => true
449-
];
440+
if ($relation instanceof HasOne || $relation instanceof HasMany) {
441+
$this->relations[$fieldName]["fields"][] = $singular;
450442
}
451443
else {
452-
if (isset($singular)) {
453-
$this->relations[$parent]["fields"][] = $singular;
444+
// The parent might already been set because we cannot rely on order
445+
// in which user sends relations in request
446+
if (!isset($this->relations[$parent])) {
447+
$this->relations[$parent] = [
448+
"limit" => config("api.defaultLimit"),
449+
"offset" => 0,
450+
"order" => "chronological",
451+
"fields" => isset($singular) ? [$singular] : [],
452+
"userSpecifiedFields" => true
453+
];
454+
}
455+
else {
456+
if (isset($singular)) {
457+
$this->relations[$parent]["fields"][] = $singular;
458+
}
454459
}
455460
}
456461

0 commit comments

Comments
 (0)