Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix EntityRepository::addSearchClause for nested Entities not joining all Tables #5671

Open
wants to merge 1 commit into
base: 4.x
Choose a base branch
from

Conversation

derpue
Copy link

@derpue derpue commented Mar 11, 2023

Bug is easiest explained with an example:

You have a (sport) player.
Each player belongs to a club. Each club has a name.

Now you have an Entity for a Match, with ManyToOne to PlayerA and ManyToOne to PlayerB.

You want to be able to (also) search in the Crud Controller for the clubs name, as such you set
->setSearchFields(['PlayerA.club.name', 'PlayerB.club.name'])

The generated search Query only contains one join for the (first) club but not the second one. But these are different Entities.

In the addSearchClause method of EntityRepository there is a check for already joined Entities, only using the Entities Name (here 'club'), resulting in this (imho wrong) behavior.

This PR should fix this by using the whole property path (PlayerA.club) as entry in the $entitiesAlreadyJoined Array while also change the way the join aliases are generated to prevent alias clashs.

Please note:
Due to server constraints outside of my control i'm still on EA 3.x, but the problematic part of ORM\EntityRepository.php didn't changed in EA 4.x. This fix works fine for me, but i'm not that deep into the codebase for EA to oversee all possible consequences. So please feel free to adopt or discard this PR as needed.

Edit: sorry for the force-pushes to get the checks passed.

@derpue derpue force-pushed the fix_addSearchClause_entitiesAlreadyJoined branch 2 times, most recently from 12792fc to 42ee57a Compare March 11, 2023 15:35
* use the whole nested path to check for an already joined Entity
* generate unique join aliases to prevent possible errors with duplicate aliases
@derpue derpue force-pushed the fix_addSearchClause_entitiesAlreadyJoined branch from 42ee57a to 6c06a52 Compare March 11, 2023 15:37
@javiereguiluz javiereguiluz added this to the 4.x milestone Apr 21, 2023
@tim18ter
Copy link

tim18ter commented Jul 3, 2023

Im wondering why this isnt allready supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants