api-platform / api-platform/core

LinksHandlerTrait still uses deprecated WITH join for owning-side to-one links (doctrine/orm#12192)

オープン 初心者向け
#8,394 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る
stale
主要言語
PHP
スター
2.6k
フォーク
980
平均マージ
2日 4時間
マージ済み PR(30日)
49

説明

**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.

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

評価

技術スタック
php
領域
backend, databases
issue の種類
バグ
難易度
1/5
見積もり時間
1時間未満
活発さ
活発
明瞭さ
明確に書かれている
初心者へのやさしさ
90/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。