It seems order by fields are not checked at all when order is given as the new \SortDirection enum (polyfilled on PHP 8.5 in this case).
<?php
namespace App\Entity;
use App\Repository\TestRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: TestRepository::class)]
class Test
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
public int $id;
#[ORM\Column]
public string $name;
}
<?php
namespace App\Repository;
use App\Entity\Test;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Test>
*/
class TestRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Test::class);
}
/**
* @return list<Test>
*/
public function test(): array
{
return $this->createQueryBuilder('t')
->orderBy('t.nonexistent2', \SortDirection::Ascending)
->getQuery()
->getResult()
;
}
}
It seems order by fields are not checked at all when order is given as the new \SortDirection enum (polyfilled on PHP 8.5 in this case).