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

[Feature] Searching by related entities fields #1991

Closed
wants to merge 3 commits into from
Closed

[Feature] Searching by related entities fields #1991

wants to merge 3 commits into from

Conversation

jazithedev
Copy link
Contributor

Related with #1910

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?
@maximecolin
Copy link
Contributor

@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

@jazithedev
Copy link
Contributor Author

You're right. Merged your changes. Thanks for help! :)

[$fieldPrefix, $name] = explode('.', $name);

if (!in_array($fieldPrefix, $joined)) {
$queryBuilder->join('entity.'.$fieldPrefix, $fieldPrefix);
Copy link
Contributor

@glaubinix glaubinix Jan 26, 2018

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.

@alterphp
Copy link
Contributor

@ktrzos It looks good. This is a very needed feature ;-)

@javiereguiluz
Copy link
Collaborator

@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!

javiereguiluz added a commit that referenced this pull request Feb 10, 2018
…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
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.

None yet

5 participants