mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-07-11 01:24:46 +02:00
fix(graphql): fix sort by relation (#967)
This commit is contained in:
@@ -74,6 +74,20 @@ trait SortsModels
|
||||
}
|
||||
|
||||
if ($sortType === SortType::RELATION) {
|
||||
if ($relation === null) {
|
||||
throw new InvalidArgumentException("The 'relation' argument is required for the {$column} column with aggregate sort type.");
|
||||
}
|
||||
|
||||
$builder->withAggregate([
|
||||
"$relation as {$relation}_$column" => function ($query) use ($column, $direction) {
|
||||
$query->orderBy($column, $direction);
|
||||
},
|
||||
], $column);
|
||||
|
||||
$builder->orderBy("{$relation}_$column", $direction);
|
||||
}
|
||||
|
||||
if ($sortType === SortType::COUNT_RELATION) {
|
||||
if ($relation === null) {
|
||||
throw new InvalidArgumentException("The 'relation' argument is required for the {$column} column with relation sort type.");
|
||||
}
|
||||
|
||||
@@ -10,4 +10,5 @@ enum SortType: int
|
||||
case ROOT = 1;
|
||||
case AGGREGATE = 2;
|
||||
case RELATION = 3;
|
||||
case COUNT_RELATION = 4;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ class CountField extends Field implements DisplayableField, SortableField
|
||||
|
||||
public function sortType(): SortType
|
||||
{
|
||||
return SortType::RELATION;
|
||||
return SortType::COUNT_RELATION;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user