diff --git a/src/Translatable/Query/TreeWalker/TranslationWalker.php b/src/Translatable/Query/TreeWalker/TranslationWalker.php index 43f613fe25..cb2055f35a 100644 --- a/src/Translatable/Query/TreeWalker/TranslationWalker.php +++ b/src/Translatable/Query/TreeWalker/TranslationWalker.php @@ -79,6 +79,13 @@ class TranslationWalker extends SqlWalker */ public const HYDRATE_SIMPLE_OBJECT_TRANSLATION = '__gedmo.translatable.simple_object.hydrator'; + /** + * Name for "only fields" hint + * + * @internal + */ + const HINT_ONLY_FIELDS = '__gedmo.translatable.only_fields'; + /** * Stores all component references from select clause * @@ -272,6 +279,7 @@ private function prepareTranslatedComponents(): void $ea->setEntityManager($em); $quoteStrategy = $em->getConfiguration()->getQuoteStrategy(); $joinStrategy = $q->getHint(TranslatableListener::HINT_INNER_JOIN) ? 'INNER' : 'LEFT'; + $onlyFields = $q->getHint(self::HINT_ONLY_FIELDS); foreach ($this->translatedComponents as $dqlAlias => $comp) { /** @var ClassMetadata $meta */ @@ -281,6 +289,13 @@ private function prepareTranslatedComponents(): void $transMeta = $em->getClassMetadata($transClass); $transTable = $quoteStrategy->getTableName($transMeta, $this->platform); foreach ($config['fields'] as $field) { + if ($onlyFields) { + $checkField = $dqlAlias.'.'.$field; + if (!\in_array($checkField, $onlyFields, true)) { + continue; + } + } + $compTblAlias = $this->walkIdentificationVariable($dqlAlias, $field); $tblAlias = $this->getSQLTableAlias('trans'.$compTblAlias.$field); $sql = " {$joinStrategy} JOIN ".$transTable.' '.$tblAlias;