question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

QueryBuilder alias Bug with custom filter [2.3.6]

See original GitHub issue

I 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:open
  • Created 4 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
soyukacommented, May 5, 2019
0reactions
teohhanhuicommented, May 6, 2019

@antograssiot The bug is still valid regardless.

Read more comments on GitHub >

github_iconTop Results From Across the Web

filter query on multiple fields in single query - Stack Overflow
I made such a custom filter for chapter 6 of my tutorial. ... private function addWhere($queryBuilder, $word, $parameterName) { $alias ...
Read more >
jQuery QueryBuilder
jQuery plugin for user friendly query/filter creator. Download ... false, Sort filters alphabetically, or with a custom function (passed to Array.sort ).
Read more >
Hibernate ORM 5.3.28.Final User Guide - Red Hat on GitHub
2.3.6. Custom BasicTypes. Hibernate makes it relatively easy for developers to ... Filtering by the Caption property using the Java Object representation.
Read more >
Backward-incompatible changes highlights - Adobe Developer
You use a custom configuration for TinyMCE that uses the tinymce4 alias in requirejs ... changes to the Magento\Email\Model\Template\Filter class.
Read more >
Filtering | laravel-query-builder - Spatie
Custom filters are instances of invokable classes that implement the \Spatie\QueryBuilder\Filters\Filter interface. The __invoke method will receive the current ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found