From 09437e2ba9e19bcba6f9ef5f004912a3725309bb Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 13 Sep 2023 10:30:16 +0200 Subject: [PATCH] Initialize proxy objects if necessary (#64) Co-authored-by: Alex C --- src/Model/TranslatableTrait.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Model/TranslatableTrait.php b/src/Model/TranslatableTrait.php index bd4a8d0..0bf18e2 100644 --- a/src/Model/TranslatableTrait.php +++ b/src/Model/TranslatableTrait.php @@ -8,6 +8,7 @@ use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Criteria; use Doctrine\Common\Collections\Expr\Comparison; +use Doctrine\Persistence\Proxy; /** * @see TranslatableInterface @@ -50,6 +51,10 @@ public function __construct() */ public function getTranslation(?string $locale = null): TranslationInterface { + if ($this instanceof Proxy && !$this->__isInitialized()) { + $this->__load(); + } + $locale = $locale ?: $this->currentLocale; if (null === $locale) { throw new \RuntimeException('No locale has been set and current locale is undefined.');