Skip to content

Doctrine ORM Filters should be able to use doctrine expressions as Join conditions. #5648

@mrossard

Description

@mrossard

API Platform version(s) affected: 3.1.x

Description
Currently APIP assumes that Doctrine\ORM\Query\Expr`\Join::getCondition() returns a string and uses it as such in ApiPlatform\Doctrine\Orm\Extension\FilterEagerLoadingExtension (see here, it's used in preg_replace :

$condition = preg_replace($this->buildReplacePatterns($aliases), $replacements, $joinPart->getCondition() ?? '');
).
If you try using a Doctrine Expr instead, you unsurprinsingly get an error similar to

preg_replace(): Argument #3 ($subject) must be of type array|string, Doctrine\ORM\Query\Expr\Comparison give

How to reproduce
Have a custom filter that adds a join($stuff, $alias, Join::WITH, $queryBuilder->expr()->like('whatever', 'something')).
Use it in conjunction with a "normal" SearchFilter.

Possible Solution
Testing whether getCondition() returns an Expr and convert it into a string maybe? Doctrine should have a usable utility somewhere, but i haven't looked into it yet.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions