Skip to content

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

Description

@tacman

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions