Skip to content

Error using an AssociationField with a nested property since v4.27.0Β #7214

@screenflavor

Description

@screenflavor

After updating to EAB version 4.27.0 I get an error on one of my index sites:

The "ccm.company" field is not a Doctrine association, so it cannot be used as an association field.

I use an AssociationField with the following syntax:

yield AssociationField::new('ccm.company', 'Company')
            ->setCrudController(CompanyCrudController::class);

ccm and company are many to one relations in their respective parent entity. I use the AssociationField to have a clickable value in the Company column. It still works when I change to TextField for example.

A bit of debugging showed me that the validation of the property names changed in the AssociationConfigurator from

    public function configure(FieldDto $field, EntityDto $entityDto, AdminContext $context): void
    {
        $propertyName = $field->getProperty();
        if (!$entityDto->isAssociation($propertyName)) {
            throw new \RuntimeException(sprintf('The "%s" field is not a Doctrine association, so it cannot be used as an association field.', $propertyName));
        }
...
    public function isAssociation(string $propertyName): bool
    {
        return $this->metadata->hasAssociation($propertyName)
            || (str_contains($propertyName, '.') && !$this->isEmbeddedClassProperty($propertyName)); <--- allows nested properties
    }

to

    public function configure(FieldDto $field, EntityDto $entityDto, AdminContext $context): void
    {
        $propertyName = $field->getProperty();
        if (!$entityDto->getClassMetadata()->hasAssociation($propertyName)) {
            throw new \RuntimeException(sprintf('The "%s" field is not a Doctrine association, so it cannot be used as an association field.', $propertyName));
        }

Is there any plan to fix this and allow nested properties here? Or am I using this in a wrong way? Until now it worked for me.

Thank you in advance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions