Skip to content

Instantly share code, notes, and snippets.

@damienalexandre
Created May 22, 2012 13:32
Show Gist options
  • Save damienalexandre/2769074 to your computer and use it in GitHub Desktop.
Save damienalexandre/2769074 to your computer and use it in GitHub Desktop.
How to use the translationClass option in the default Translatable repository
diff --git a/lib/Gedmo/Translatable/Entity/Repository/TranslationRepository.php b/lib/Gedmo/Translatable/Entity/Repository/TranslationRepository.php
index 50b106e..2451fd0 100644
--- a/lib/Gedmo/Translatable/Entity/Repository/TranslationRepository.php
+++ b/lib/Gedmo/Translatable/Entity/Repository/TranslationRepository.php
@@ -64,9 +64,14 @@ class TranslationRepository extends EntityRepository
$entityClass = $wrapped->getMetadata()->name;
$translationMeta = $this->getClassMetadata(); // table inheritance support
+
+ // Get the custom translationClass
+ $config = $this->getTranslationListener()->getConfiguration($this->_em, get_class($entity));
+ $translationClass = isset($config['translationClass']) ? $config['translationClass'] : $translationMeta->rootEntityName ;
+
$qb = $this->_em->createQueryBuilder();
$qb->select('trans.content, trans.field, trans.locale')
- ->from($translationMeta->rootEntityName, 'trans')
+ ->from($translationClass, 'trans')
->where('trans.foreignKey = :entityId', 'trans.objectClass = :entityClass')
->orderBy('trans.locale');
$q = $qb->getQuery();
@Gounlaf
Copy link

Gounlaf commented Feb 23, 2014

Hi,

I know you have do this a long time ago, but is it still working ?
I found the issue (https://github.com/l3pp4rd/DoctrineExtensions/issues/167) and your patch is not available =/

Is this a good way to do, or there is another way now ?

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment