Skip to content

Commit

Permalink
added selective field translation to the translateable extension
Browse files Browse the repository at this point in the history
  • Loading branch information
smatyas committed Oct 3, 2024
1 parent ade7387 commit 05072ed
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Translatable/Query/TreeWalker/TranslationWalker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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 */
Expand All @@ -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;

Check warning on line 295 in src/Translatable/Query/TreeWalker/TranslationWalker.php

View check run for this annotation

Codecov / codecov/patch

src/Translatable/Query/TreeWalker/TranslationWalker.php#L293-L295

Added lines #L293 - L295 were not covered by tests
}
}

$compTblAlias = $this->walkIdentificationVariable($dqlAlias, $field);
$tblAlias = $this->getSQLTableAlias('trans'.$compTblAlias.$field);
$sql = " {$joinStrategy} JOIN ".$transTable.' '.$tblAlias;
Expand Down

0 comments on commit 05072ed

Please sign in to comment.