QueryBuilder alias Bug with custom filter [2.3.6]
See original GitHub issueI have a strange behavior when I use a custom filter with a value equal to the alias of the query builder.
I have a Client that have OneToOne relation with Contact , Contact have 2 properties email and professionalEmail I create a custom OR filter in order to filter on these properties.
When I get api/clients?contact.email=email@yahoo.com the SQL QUERY is
SELECT count(DISTINCT c0_.id) AS sclr_0 FROM client c0_ INNER JOIN
client_contact c1_ ON c0_.contact_id = c1_.id
WHERE c0_.id IN (SELECT c2_.id FROM client c2_ INNER JOIN client_contact c3_
ON c2_.contact_id = c3_.id WHERE c3_.email
LIKE '%email@yahoo_a1.com%'
OR c3_.professional_email LIKE '%email@yahoo_a1.com%')
The value email@yahoo.com is transformed to email@yahoo_a1.com and I don’t have any result, all value that end with o. are transformed to _aNumberOfRelation
My clue was to redefine the alias in https://github.com/api-platform/core/blob/master/src/Bridge/Doctrine/Orm/CollectionDataProvider.php#L67 but IMO the problem comes from FilterEagerLoadingExtension::getQueryBuilderWithNewAliases
TBH I don’t know if it’s a bug or if my filter is wrong ? There is a small example to reproduce the bug https://github.com/ismail1432/reproduce-filter-bug-api-platform , Fixtures are in migrations.
Solution
~Change the way the value are given in FilterEagerLoadingExtension::getQueryBuilderWithNewAliases~ 😕
Or prevent that aliases are different than the value to filter.
in the CollectionDataProvider for the root alias and in QueryNameGenerator for the joinAlias
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (4 by maintainers)

Top Related StackOverflow Question
https://github.com/api-platform/core/issues/2763 related?
@antograssiot The bug is still valid regardless.