Open Naroh091 opened 2 years ago
Seems like surrounding the lines referring to the instance with a try/catch block does the trick:
try {
$relatedEntityId = $accessor->getValue($entityDto->getInstance(), $propertyName . '.' . $metadata->getIdentifierFieldNames()[0]);
$relatedEntityDto = $this->entityFactory->create($targetEntityFqcn, $relatedEntityId);
$field->setFormTypeOptionIfNotSet('class', $relatedEntityDto->getFqcn());
$field->setCustomOption(AssociationField::OPTION_RELATED_URL, $this->generateLinkToAssociatedEntity($targetCrudControllerFqcn, $relatedEntityDto));
$field->setFormattedValue($this->formatAsString($relatedEntityDto->getInstance(), $relatedEntityDto));
} catch (\Exception $e) {
}
But surely there's a better approach to fix the issue.
@Naroh091 I made a PR with the embedded associations and now made a fix for this #4786, though granted it's basically the same, just more specific. Sorry for the trouble, I only found it today - I wasn't able to fully test it in our live app enough and I guess it broke a few things.
Describe the bug Adding an embedded association to CRUD controllers break the ability of adding filters to the controller.
To Reproduce
Classes: Donation, Subscription, and User.
Donation has a ManyToOne relationship with Subscription. Subscription has an OneToOne subscription with User.
In the Donation CRUD controller I'm showing the associated User this way:
yield AssociationField::new('subscription.user', 'Usuario')->setCrudController(User::class);
So far, this works fine.
Then, if I add a simple NumericFilter to show the amount of the donation:
I get the following error when I open the filters modal:
The issue is that in AssociationConfigurator.php, line 82, the instance that should be returned with
$entityDto->getInstance()
is null.If I remove the AssociationField then that part of the code that checks for embedded association doesn't get executed and everything works fine.
Happening with the latest version of EasyAdmin, v3.5.10