Skip to content

Commit

Permalink
fix(graphql): HasOneThrough sorting fix (Laravel v11.15.0 compatibi…
Browse files Browse the repository at this point in the history
…lity).

(cherry picked from commit 2fa609f)
  • Loading branch information
LastDragon-ru committed Jul 13, 2024
1 parent ff8650a commit bbecb7c
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/graphql/src/SortBy/Sorters/EloquentSorter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
use Illuminate\Database\Eloquent\Relations\HasOneOrMany;
use Illuminate\Database\Eloquent\Relations\HasOneOrManyThrough;
use Illuminate\Database\Eloquent\Relations\MorphOneOrMany;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Database\Query\JoinClause;
Expand All @@ -19,6 +20,7 @@
use Override;

use function array_shift;
use function class_exists;

/**
* @extends DatabaseSorter<EloquentBuilder<Model>>
Expand Down Expand Up @@ -157,7 +159,12 @@ static function (JoinClause $join) use ($relation, $currentAlias, $parentAlias):
? "{$parentAlias}.{$relation->getLocalKeyName()}"
: $relation->getQualifiedParentKeyName(),
);
} elseif ($relation instanceof HasManyThrough) {
} elseif (
$relation instanceof HasManyThrough
|| ( // Since Laravel v11.15.0
class_exists(HasOneOrManyThrough::class) && $relation instanceof HasOneOrManyThrough
)
) {
$builder->joinSub(
$relation->getQuery()->select([
"{$relation->getParent()->getQualifiedKeyName()} as {$currentAlias}_key",
Expand Down

0 comments on commit bbecb7c

Please sign in to comment.