Skip to content

Commit 46e04cb

Browse files
author
Mikk Mihkel Nurges
authored
SelectFields foreign key fix (#176)
1 parent 3c4b7e9 commit 46e04cb

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/Rebing/GraphQL/Support/SelectFields.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Rebing\GraphQL\Support;
44

5+
use function array_key_exists;
56
use Closure;
67
use GraphQL\Error\InvariantViolation;
78
use GraphQL\Type\Definition\InterfaceType;
@@ -195,13 +196,10 @@ protected static function handleFields(array $requestedFields, $parentType, arra
195196
}
196197
}
197198
// If 'HasMany', then add it in the 'with'
198-
elseif(is_a($relation, HasMany::class) || is_a($relation, MorphMany::class) || is_a($relation, HasOne::class))
199+
elseif((is_a($relation, HasMany::class) || is_a($relation, MorphMany::class) || is_a($relation, HasOne::class))
200+
&& !array_key_exists($foreignKey, $field))
199201
{
200-
$foreignKey = explode('.', $foreignKey)[2];
201-
if( ! array_key_exists($foreignKey, $field))
202-
{
203-
$field[$foreignKey] = self::FOREIGN_KEY;
204-
}
202+
$field[$foreignKey] = self::FOREIGN_KEY;
205203
}
206204

207205
// New parent type, which is the relation

0 commit comments

Comments
 (0)