-
-
Notifications
You must be signed in to change notification settings - Fork 960
Open
Description
API Platform version(s) affected: 4.2.17
Description
We use the new feature about UriVariables, and it works well with DTO.
But with doctrine entities, it does not work as expected:
new GetCollection(
uriTemplate: '/redirection-plans/{plan}/pairings',
uriVariables: [
'plan' => new Link(
fromClass: Plan::class,
provider: ReadLinkParameterProvider::class,
security: "true", // We fake it, so simplify the reproducer !
),
],
security: 'true', // Security is done at the uriVariable level
),It genereted this kind of doctrine SQL:
SELECT o FROM App\Entity\Pairing o WHERE o_a1.id = :id_p1Then it crashes:
[Semantical Error] line 0, col 41 near 'o_a1.id = :id_p1': Error: 'o_a1' is not defined.
How to reproduce
I created a reproducer, you clone it, install it, start a webserver, then run:
curl --request GET \
--url https://127.0.0.1:8000/api/redirection-plans/3b78b4d3-f292-4876-85e4-7d5be788d18c/pairings
Possible Solution
I think the culprit is here:
core/src/Doctrine/Orm/State/LinksHandlerTrait.php
Lines 71 to 77 in 06f66f9
| $currentAlias = $fromClass === $entityClass ? $alias : $queryNameGenerator->generateJoinAlias($alias); | |
| foreach ($identifierProperties as $identifierProperty) { | |
| $placeholder = $queryNameGenerator->generateParameterName($identifierProperty); | |
| $queryBuilder->andWhere("$currentAlias.$identifierProperty = :$placeholder"); | |
| $queryBuilder->setParameter($placeholder, $this->getIdentifierValue($identifiers, $hasCompositeIdentifiers ? $identifierProperty : null), $fromClassMetadata->getTypeOfField($identifierProperty)); | |
| } |
This code lost some information, and use the queryNameGenerator to get the current alias. But there is no alias here (o) !
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels