Fix filters on nested associations and embedded properties#7500
Fix filters on nested associations and embedded properties#7500Seb33300 wants to merge 1 commit intoEasyCorp:5.xfrom
Conversation
18c6ca4 to
646cbcb
Compare
a009235 to
6a93dff
Compare
6a93dff to
1b66e5e
Compare
|
Just found an issue with the EntityFilter + nested associations, I am investigating. |
9fbf27a to
1a53387
Compare
| * property_name: string, | ||
| * } | ||
| */ | ||
| public function resolveNestedAssociations(?QueryBuilder $queryBuilder, EntityDto $rootEntityDto, string $propertyName, bool $mustEndWithAssociation = false): array |
There was a problem hiding this comment.
While extracting that logic from search, I also modified:
$queryBuilderis nullable so theresolveNestedAssociations()method can be called to resolve the nestedEntityDto& property name without applying the joins to the query (eg:EntityConfiguratoruse it to resolve the entity used to fetch choice list)$mustEndWithAssociationis used to allow property ending on an association field (eg:post.authorinstead ofpost.author.fullName) as required byEntityFilter
|
Issue on |
4823239 to
4758cb5
Compare
| // Fallback to support custom filters with unmapped property names | ||
| $resolvedProperty = [ | ||
| 'entity_dto' => $entityDto, | ||
| 'entity_alias' => current($queryBuilder->getRootAliases()), | ||
| 'property_name' => $originalPropertyName, | ||
| ]; |
There was a problem hiding this comment.
Without this fallback, AuthorWithMinPostsFilter was not working in the EasyAdmin demo project.
There was a problem hiding this comment.
Note about this:
Instead of try/catch, it would be cleaner to check if the filter is unmapped.
This may be achieved by checking the related form option as suggested by EA documentation:
https://symfony.com/bundles/EasyAdminBundle/current/filters.html#unmapped-filters
However, it looks like previous code was working on unmapped fields even if the mapped option was not specified.
For example, the custom filter from EA demo is not defining the mapped option, and it still work:
https://github.com/EasyCorp/easyadmin-demo/blob/main/src/Admin/Filter/AuthorWithMinPostsFilter.php
And if we replace the try/catch by a check on the form type option, this may introduce a BC break on unmapped filter that does not specify the unmapped option, but this should also fix this bug: #6386
There was a problem hiding this comment.
5ddf42f to
e8ad127
Compare
e8ad127 to
1be57a5
Compare
Same as #7295 with a different approach.
Fixes #7452 and #6664
In
resolveNestedAssociations()I have extracted the logic handling nested associations from search to make it reusable in filters.It also properly handles doctrine embeddables.
It's now possible to use associations in filters using the dot syntax: