Skip to content

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

@McLone

Description

@McLone

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 👍

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions