DoctrineBehaviors icon indicating copy to clipboard operation
DoctrineBehaviors copied to clipboard

Translatable classes not working with orm lazyGhostObjects enabled

Open mmarton opened this issue 2 years ago • 1 comments

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

mmarton avatar Jan 12 '23 15:01 mmarton

Not helped for me, resolved by redefine Knp\DoctrineBehaviors\Model\Translatable\TranslatableMethodsTrait::getTranslationEntityClass in entity:

public static function getTranslationEntityClass(): string
{
    return self::class.'Translation';
}

wyster avatar Feb 27 '23 21:02 wyster