api-platform / api-platform/core

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

Đang mở Phù hợp với người mới
#8,394 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
stale
Ngôn ngữ chính
PHP
Star
2.6k
Fork
980
Merge trung bình
2 ngày 4 giờ
Pull request đã merge (30 ngày)
49

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
php
Lĩnh vực
backend, databases
Loại issue
Lỗi
Độ khó
1/5
Thời gian dự kiến
Dưới một giờ
Mức độ hoạt động
Sôi nổi
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
90/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.