core
core copied to clipboard
Unable to use HIDDEN fields in an ORM query within a custom Filter
API Platform version(s) affected: 3.2.14
Description
I'm trying to create a custom filter that simply adds a special OrderBy to the QueryBuilder. This query requires the use of HIDDEN
fields so Doctrine can sort by them. This query works in my non-api code. However, api-platform seems to think these values are joins and not fields and thus throws an exception of The alias "..." does not exist in the QueryBuilder.
.
How to reproduce
protected function filterProperty(string $property, $value, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, ?Operation $operation = null, array $context = []): void
{
if ($property !== $this->searchTerm || !is_array($value)) {
return;
}
if (!empty($value['template_order'])) {
$a = $queryBuilder->getRootAliases()[0];
$queryBuilder
->addSelect("CASE WHEN $a.enabled = 1 THEN 0 ELSE 1 END AS HIDDEN enabled")
->addSelect("CASE WHEN $a.quick = 1 THEN 0 ELSE 1 END AS HIDDEN quick")
->orderBy("enabled, quick, $a.title");
}
}
Possible Solution
Additional Context
What's the stack trace? Possible to have a reproducer? This should definitely work
I can't do a reproducer at this time. But the stack trace is attached (JSON response): stack trace.txt
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.