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

EmbeddedList, on empty many-to-many attributes, ignore filters #152

Open
McLone opened this issue Jul 25, 2019 · 4 comments
Open

EmbeddedList, on empty many-to-many attributes, ignore filters #152

McLone opened this issue Jul 25, 2019 · 4 comments

Comments

@McLone
Copy link

McLone commented Jul 25, 2019

Hi!

It looks like the url generated for the subquery drops the "filters" attribute on Generator/UrlGenerator.php:275 in symfony/routing v4.2.10 (but I guess it should impact all versions) :

if ($extra && $query = http_build_query($extra, '', '&', PHP_QUERY_RFC3986)) {

$extra does have a key 'filters' with an array 'entity.id' => [], but http_build_query seems to not like empty array and does'nt put filters in its query (see https://stackoverflow.com/questions/2930592/http-build-query-ignores-the-key-if-the-value-is-an-empty-array-how-is-this-not).

A quick and dirty fix would be to replace, in src/Helper/EmbeddedListHelper.php:144 (v2.1.6) :

return ['entity.id' => $itemIds->toArray()];

by

$array = $itemIds->toArray();
if(empty($array)) {
    $array = [0];
}
return ['entity.id' => $array];

... but only works if we're sure to never have entities with "0" id.

Thanks to all contributor of this bundle 👍

@alterphp
Copy link
Owner

Hi @McLone !

Empty arrays are ignored by dynamic filtered queries. This is a known limitation, and I prefer not to try to work around this.

Which case are trying to solve. Can't you test if your value list is not empty before generating the URL ?

@McLone
Copy link
Author

McLone commented Jul 25, 2019

@alterphp
I'm not sure a test would apply on my case :

I have the following configuration:

entities:
    User:
        class: App\Entity\User
        show:
            fields:
                - email
                - { property: 'cars', label: 'Cars', type: embedded_list }

with cars having a many-to-many relation.

When I'm in the "show" of a user with no car assigned, I expect to see an "empty result", but I see all cars of my database.

@botjaeger
Copy link

@McLone thanks for this, I just decorated this service alterphp.easyadmin_extension.helper.embedded_list with your workaround.

@Chrisissorry
Copy link

Chrisissorry commented Oct 2, 2019

I guess I am experiencing the same problem here. I also have a many-to-many relation.

easy_admin:
    entities:
        Assessment:
            class: App\Entity\Assessment
            form:
                fields:
                    - externalReference
                    - seniorityLevel
                    - tags
                    - { property: questions, type: embedded_list }

It shows all questions at all times. My expectation was that it actually only shows the ones actually related to Assessment.

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

No branches or pull requests

4 participants