mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-09-05 20:25:05 +02:00
34 lines
972 B
PHP
34 lines
972 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Api\Field\Base;
|
|
|
|
use App\Http\Api\Criteria\Include\Criteria;
|
|
use App\Http\Api\Field\IntField;
|
|
use App\Http\Api\Query\Query;
|
|
use App\Http\Api\Schema\Schema;
|
|
use App\Http\Resources\BaseJsonResource;
|
|
|
|
class IdField extends IntField
|
|
{
|
|
public function __construct(Schema $schema, string $column)
|
|
{
|
|
parent::__construct($schema, BaseJsonResource::ATTRIBUTE_ID, $column);
|
|
}
|
|
|
|
public function shouldSelect(Query $query, Schema $schema): bool
|
|
{
|
|
// We can only exclude ID fields for top-level models that are not including related resources.
|
|
$includeCriteria = $query->getIncludeCriteria($this->schema->type());
|
|
if (
|
|
$this->schema->type() === $schema->type()
|
|
&& (! $includeCriteria instanceof Criteria || $includeCriteria->getPaths()->isEmpty())
|
|
) {
|
|
return parent::shouldSelect($query, $schema);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|