This commit is contained in:
Dan Harrin
2024-01-08 10:49:00 +00:00
parent 7a1d95ce6a
commit d3ccbeda3f
2 changed files with 18 additions and 4 deletions
@@ -55,6 +55,8 @@ trait CanGroupRecords
$group->applyEagerLoading($query);
return $group->orderQuery($query, $this->getTableGroupingDirection() ?? 'asc');
$group->orderQuery($query, $this->getTableGroupingDirection() ?? 'asc');
return $query;
}
}
+15 -3
View File
@@ -8,7 +8,6 @@ use Closure;
use DateTimeInterface;
use Filament\Support\Components\Component;
use Filament\Support\Contracts\HasLabel as LabelInterface;
use Filament\Tables\Columns\Concerns\InteractsWithTableQuery;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Eloquent\Model;
@@ -18,8 +17,6 @@ use Illuminate\Support\Arr;
class Group extends Component
{
use InteractsWithTableQuery;
protected ?string $column;
protected ?Closure $getDescriptionFromRecordUsing = null;
@@ -457,4 +454,19 @@ class Group extends Component
{
return $this->isDate;
}
public function applyEagerLoading(EloquentBuilder $query): EloquentBuilder
{
if (! $this->getRelationship($query->getModel())) {
return $query;
}
$relationshipName = $this->getRelationshipName();
if (array_key_exists($relationshipName, $query->getEagerLoads())) {
return $query;
}
return $query->with([$relationshipName]);
}
}