Fix EntityRepository::addSearchClause for nested Entities not joining all Tables #5671
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.