DoctrineBehaviors
DoctrineBehaviors copied to clipboard
Translatable classes not working with orm lazyGhostObjects enabled
Hi!
enable_lazy_ghost_objects: true
became the default config for doctrinebundle
https://github.com/symfony/recipes/pull/1140
With it turned on I got this error from any translatable entity:
Proxies\__CG__\...\Entity\PageTranslation::createLazyGhost(): Argument #1 ($initializer) must be of type Closure|array, null given
this is because by default the translation property is not initialized by default as ArrayCollection in TranslatablePropertiesTrait.
related: https://github.com/doctrine/orm/issues/10376
tldr: from now, you have to have
public function __construct()
{
$this->translations = new ArrayCollection();
}
in your translatable classes
Not helped for me, resolved by redefine Knp\DoctrineBehaviors\Model\Translatable\TranslatableMethodsTrait::getTranslationEntityClass
in entity:
public static function getTranslationEntityClass(): string
{
return self::class.'Translation';
}