EasyAdminBundle icon indicating copy to clipboard operation
EasyAdminBundle copied to clipboard

Filters throw exception on transitive association field in field configuration

Open siggidiel opened this issue 1 year ago • 0 comments

Describe the bug I have 3 entities:

  • Talk (Represents a expert talk (webinar) where normal users can participate in video calls)
  • Expert (Represents the expert holding the webinar and presenting the course in the call)
  • TalkSubscription (Represents participations to a talk with the logged in user IDs)

Relations are as follows:

  • Talk < OneToMany > TalkSubscription (1 talk can have multiple subscriptions. But 1 subscription can only have 1 talk)
  • Talk < ManyToOne > Expert (1 talk can only have 1 expert. But 1 expert can have multiple talks)

I am on the crud controller of TalkSubscription and I want to display 2 AssociationField columns:

  • I want to show the associated talk: TalkSubscription -> Talk
  • I want to show the talk's associated expert: TalkSubscription -> Talk -> Expert (Transitive relation)

I made it by configuring the fields as following:

public function configureFields(string $pageName): iterable
{
    return match ($pageName) {
        Crud::PAGE_INDEX, Crud::PAGE_DETAIL => [
            IdField::new('ssoUserId')->setFormType(UuidType::class),
            AssociationField::new('talk'),
            // Seems like the the controller explicitly needs to be set for the transitive relation. 
            // Otherwise, exception occurs
            AssociationField::new('talk.expert')->setCrudController(ExpertCrudController::class),
        ],
        default => []
    };
}

This works fine. But as soon as I open filters, I get this exception:

Symfony\Component\PropertyAccess\PropertyAccessor::getValue(): Argument #1 ($objectOrArray) must be of type object|array, null given, called in /var/www/web-backoffice-expert-talk/vendor/easycorp/easyadmin-bundle/src/Field/Configurator/AssociationConfigurator.php on line 123

This is my filter setup. Nothing special at the moment:

public function configureFilters(Filters $filters): Filters
{
    return $filters->add(TextFilter::new('ssoUserId'));
}

Only when removing the transitive AssociationField::new('talk.expert') field from my field configuration, the filter is working.

(OPTIONAL) Additional context This is the AJAX response (StatusCode 500) from the filters:

image

siggidiel avatar Aug 30 '24 09:08 siggidiel