Skip to content

Filter on property of an entity in a many-to-one relation #4966

@ToshY

Description

@ToshY

Describe the bug
After not being able to find in the docs on how to apply a filter based on a property of the entity I'd like to ask if it's even possible.

To Reproduce
As an example, I have have a many-to-one relation from User to Colour denoted with the property userColour. The Colour entity consists of a property colourCode which is of type string.

In the CRUD controller for User, let's say I have the following fields configured:

return [
    AssociationField::new('userColour'),
    TextField::new('userColour.colourCode'),
];

Now I can use the EntityFilter on userColour to filter (which works), but if I wanted to filter on userColour.colourCode it doesn't seem to be that easy.

return $filters
    ->add(EntityFilter::new('userColour')) // works
    ->add(EntityFilter::new('userColour.colourCode')) // doesn't work

Throwing the following error/stacktrace:

Error:
Call to a member function getAsDto() on array

  at vendor/easycorp/easyadmin-bundle/src/Factory/FilterFactory.php:72
  at EasyCorp\Bundle\EasyAdminBundle\Factory\FilterFactory->create(object(FilterConfigDto), object(FieldCollection), object(EntityDto))
     (vendor/easycorp/easyadmin-bundle/src/Controller/AbstractCrudController.php:124)
  at EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController->index(object(AdminContext))
     (vendor/symfony/http-kernel/HttpKernel.php:152)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
     (vendor/symfony/http-kernel/HttpKernel.php:74)
  at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
     (vendor/symfony/http-kernel/Kernel.php:202)
  at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
     (vendor/symfony/runtime/Runner/Symfony/HttpKernelRunner.php:35)
  at Symfony\Component\Runtime\Runner\Symfony\HttpKernelRunner->run()
     (vendor/autoload_runtime.php:29)
  at require_once('/app/vendor/autoload_runtime.php')
     (public/index.php:5) 

So am I missing something obvious here, either wrongly passing the property name or missing some options? Or is this either something that isn't working correctly, or maybe should a custom filter be used for such cases?

Additional context

Versions:

  • EA: 4.0.2
  • SF: 6.0.1
  • PHP: 8.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions