Doctrine `enable_lazy_ghost_objects` option breaks Sylius translation
jbcr opened this issue · 0 comments
Sylius version affected: 1.12.0 to 1.13.2
Description
Hello, I'm upgrading a project from Sylius 1.12 to 1.13.2.
During the upgrade, I have set the enable_lazy_ghost_objects
to true
to remove deprecation.
But, if enable_lazy_ghost_objects
is true
I have an error when I try to access Sylius Ressource translation from a relation.
Related Issue : doctrine/DoctrineBundle#1809
Steps to reproduce
I added a new entity (resource) named Tag with a one-to-many relation to Product.
When I execute $tag->getFirstProduct()->getTranslation()->getName();
the exception is thrown because the product is not loaded.
When enable_lazy_ghost_objects
is false
, the proxy has a method to initialize the product entity on getTranslation()
call.
When enable_lazy_ghost_objects
is true
, the proxy does not intercept the function call and the object is not loaded.
I must call a getter manually to force the object data loading before call getTranslation()
.
Possible Solution
Check if the object is initialized and try access to the translations
property to force data loading.
Work when I add this code into vendor/sylius/resource-bundle/src/Component/Model/TranslatableTrait.php
line 50
if (!isset($this->currentLocale)) {
$this->getTranslations();
}