-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
[Feature] Searching by related entities fields #1991
Conversation
While we can make add columns of an related entity in the "list" actions, there is no way to search by them. ```yml easy_admin: entities: Campaign: list: fields: - property: name - property: domain.name // <--- ``` ```yml easy_admin: entities: Campaign: search: fields: - domain.name // <--- throwing error ``` These changes are making that it will now be possible. What do you think about it?
@ktrzos I just run into a bug with your code. When you add two fields of the same related entity, the query builder will join two time with the same alias. easy_admin:
entities:
Campaign:
search:
fields:
- domain.name # <--- first join
- domain.foobar # <--- second join Same thing if you set a sort on a related entity field. easy_admin:
entities:
Campaign:
search:
sort: ['domain.name', 'ASC'] # <--- first join
fields:
- domain.name # <--- second join Fixed with the following changes : https://github.com/ktrzos/EasyAdminBundle/pull/1 |
Fix multiple join
You're right. Merged your changes. Thanks for help! :) |
[$fieldPrefix, $name] = explode('.', $name); | ||
|
||
if (!in_array($fieldPrefix, $joined)) { | ||
$queryBuilder->join('entity.'.$fieldPrefix, $fieldPrefix); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ktrzos I just build the same feature with more or less the same code (only saw your PR when I was done).
This should be a leftJoin
same as line 94/95
. Happy to contribute tests or whatever is necessary to get this merged.
@ktrzos It looks good. This is a very needed feature ;-) |
@ktrzos thanks for your work on this and thanks everybody else for reviewing and improving it. I want to merge this soon, so I'm finishing it and adding tests to it in #2045. Thanks! |
…imecolin, javiereguiluz) This PR was merged into the 1.17.x-dev branch. Discussion ---------- Allow to search by related entities fields This finishes #1991. Commits ------- 7ed99c6 Added docs for the new feature 851fce9 Added tests for the new feature f136e6f Fix tests 6248c60 Fixed tests 6f201dd Fixes db3b4b4 Code syntax fixes and tweaks b60b986 Merge pull request #1 from maximecolin/patch-3 e73afa4 Fix multiple join 984018f Searching by related entities fields
Related with #1910