api-platform / api-platform/core
LinksHandlerTrait still uses deprecated WITH join for owning-side to-one links (doctrine/orm#12192)
- Linguagem predominante
- PHP
- Estrelas
- 2.6k
- Forks
- 980
- Merge médio
- 2d 4h
- PRs com merge (30d)
- 49
Descrição
**API Platform version(s) affected**: 4.3.16 (with doctrine/orm 3.6.7)
### Description
`ApiPlatform\Doctrine\Orm\State\LinksHandlerTrait::handleLinks()` builds a join using the deprecated arbitrary-join `WITH` syntax when resolving a link through an owning-side to-one association that was derived from the property's native type (no explicit `toProperty`):
https://github.com/api-platform/core/blob/main/src/Doctrine/Orm/State/LinksHandlerTrait.php#L121-L128
```php
} else {
$queryBuilder->join(
$fromClass,
$joinAlias,
'WITH',
"$previousAlias.{$previousJoinProperties[0]} = $joinAlias.{$associationMapping['fieldName']}"
);
}
```
Since doctrine/orm 3.5.4 (deprecation shipped ahead of schedule per doctrine/orm#12267, tracked at doctrine/orm#12192), using `WITH` for the join condition of an *arbitrary* join (as opposed to a relation join) is deprecated in favor of `ON`. This code path triggers that deprecation on every request that resolves such a link, since `QueryBuilder::join()` doesn't currently expose a way to pick `ON` instead of `WITH`.
### Reproduction
```
User Deprecated: Using WITH for the join condition of arbitrary joins is deprecated. Use ON instead. (Parser.php:1677 called by Parser.php:1549, https://github.com/doctrine/orm/issues/12192, package doctrine/orm)
```
This fires on `bin/console cache:clear` and on any request that resolves a resource via a link where:
- `link->getFromProperty()` is set and `link->getToProperty()` is not (link built from the property's native type via `LinkFactory`)
- the association is a to-one, owning-side association (`ClassMetadata::TO_MANY` branch and the non-owning-side `TO_ONE` branch already avoid `WITH`)
I don't have a minimal standalone reproducer repo handy, but the trigger condition above should be enough to reproduce with any `ApiResource` that links to a parent through an owning-side to-one property without an explicit `toProperty`.
### Possible Solution
`Doctrine\ORM\QueryBuilder::join()` accepts a `$conditionType` argument that already supports `Doctrine\ORM\Query\Expr\Join::ON` — swapping the literal `'WITH'` for `Join::ON` (or `'ON'`) at that call site should silence the deprecation without behavior changes, since the join condition here is a plain equality between two aliases (not filtering the joined *relation* itself), i.e. exactly the "arbitrary join" case the doctrine/orm deprecation is about.
### Workaround
We're suppressing the deprecation locally via `Doctrine\Deprecations\Deprecation::ignoreDeprecations('https://github.com/doctrine/orm/issues/12192')` until this is fixed upstream.
Guia de contribuição
Direção de pesquisa
Open src/Doctrine/Orm/State/LinksHandlerTrait.php around lines 121-128 and inspect the arbitrary join built in handleLinks(). Verify the Doctrine QueryBuilder condition type used there, then run the relevant existing test suite or reproduction; done means the owning-side to-one link no longer emits the Doctrine deprecated-WITH warning without changing the join behavior.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- php
- Domínio
- backend, databases
- Tipo de issue
- Bug
- Dificuldade
- 1/5
- Tempo estimado
- Menos de uma hora
- Status de atividade
- Ativa
- Clareza
- Claramente especificada
- Facilidade para iniciantes
- 90/100