core icon indicating copy to clipboard operation
core copied to clipboard

Doctrine fetchJoinCollection detection (QueryBuilderHelper)

Open benblub opened this issue 3 years ago • 1 comments

API Platform version(s) affected: 2.6.8

Description
When i use a join with a FQCN the fetchJoinCollection is false. Let me explain a bit deeper. If we look in doctrine docs all examples are written with . notation. But you can also write joins with a FQCN like $qb->leftJoin(Phonenumbers::class, 'p').

    // Example - $qb->leftJoin('u.Phonenumbers', 'p', Expr\Join::WITH, $qb->expr()->eq('p.area_code', 55))
    // Example - $qb->leftJoin('u.Phonenumbers', 'p', 'WITH', 'p.area_code = 55')
    // Example - $qb->leftJoin('u.Phonenumbers', 'p', 'WITH', 'p.area_code = 55', 'p.id')
    public function leftJoin($join, $alias, $conditionType = null, $condition = null, $indexBy = null);

In File src/Bridge/Doctrine/Orm/Extension/PaginationExtension.php QueryChecker::hasJoinedToManyAssociation is called if not attribute for fetchJoinCollection isset. Then QueryBuilderHelper::traverseJoins is called. The problem occurs then here: explode don't work because there no . in a FQCN. So $association is null that hasJoinedToManyAssociation will return false.

    private static function mapJoinAliases(iterable $joins): array
    {
        $aliasMap = [];

        foreach ($joins as $join) {
            $alias = $join->getAlias();
            $relationship = $join->getJoin();

            if (false !== strpos($relationship, '.')) {
                $aliasMap[$alias] = explode('.', $relationship);
            } else {
                $aliasMap[$alias] = $relationship;
            }
        }

        return $aliasMap;
    }

As doctrine docs show always the join examples with . notation not sure this needs a bugfix?

How to reproduce
As i described above.

Possible Solution
Add check for a FQCN.

benblub avatar Aug 17 '22 06:08 benblub

Add check for a FQCN.

:+1:

soyuka avatar Sep 16 '22 13:09 soyuka

This bug is targeting 2.7, as API Platform 3.2 is out, version 2.7 has reached end of life. Therefore we'll close this issue.

We recommend to upgrade to API Platform 3.0, Les-Tilleuls.coop can offer paid support to help or even migrate your projects if they have tests.

We want to fund a Long Term Stable version of API Platform, if you or your organization would like to contribute to LTS support, please visit our Open Collective crowdfunding.

soyuka avatar Oct 17 '23 09:10 soyuka