Doctrine enable_lazy_ghost_objects
option breaks Sylius translation
#901
Labels
Bug
Confirmed bugs or bugfixes.
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
totrue
to remove deprecation.But, if
enable_lazy_ghost_objects
istrue
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
isfalse
, the proxy has a method to initialize the product entity ongetTranslation()
call.When
enable_lazy_ghost_objects
istrue
, 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 50The text was updated successfully, but these errors were encountered: