Explorar el Código

[translatable] fix query hint to avoid joining same locale two times in case it is default closes #135

gediminasm hace 13 años
padre
commit
1f886ba317

+ 1 - 1
lib/Gedmo/Translatable/Query/TreeWalker/TranslationWalker.php

@@ -324,7 +324,7 @@ class TranslationWalker extends SqlWalker
                 $sql .= ' AND '.$tblAlias.'.'.$transMeta->getQuotedColumnName('foreignKey', $this->platform)
                 $sql .= ' AND '.$tblAlias.'.'.$transMeta->getQuotedColumnName('foreignKey', $this->platform)
                     .' = '.$compTblAlias.'.'.$colName;
                     .' = '.$compTblAlias.'.'.$colName;
                 $result[$comp['nestingLevel']] .= $sql;
                 $result[$comp['nestingLevel']] .= $sql;
-                if (strlen($defaultLocale)) {
+                if (strlen($defaultLocale) && $locale != $defaultLocale) {
                     // join default locale
                     // join default locale
                     $tblAliasDefault = $this->getSQLTableAlias('trans_default_locale'.$compTblAlias.$field);
                     $tblAliasDefault = $this->getSQLTableAlias('trans_default_locale'.$compTblAlias.$field);
                     $sql = ' LEFT JOIN '.$transTable.' '.$tblAliasDefault;
                     $sql = ' LEFT JOIN '.$transTable.' '.$tblAliasDefault;

+ 28 - 0
tests/Gedmo/Translatable/TranslationQueryWalkerTest.php

@@ -40,6 +40,34 @@ class TranslationQueryWalkerTest extends BaseTestCaseORM
         $this->populate();
         $this->populate();
     }
     }
 
 
+    public function testIssue135()
+    {
+        $this->populateIssue109();
+        $this->em
+            ->getConfiguration()
+            ->expects($this->any())
+            ->method('getCustomHydrationMode')
+            ->with(TranslationWalker::HYDRATE_OBJECT_TRANSLATION)
+            ->will($this->returnValue('Gedmo\\Translatable\\Hydrator\\ORM\\ObjectHydrator'))
+        ;
+        $query = $this->em->createQueryBuilder();
+        $query->select('a')
+            ->from(self::ARTICLE, 'a')
+            ->add('where', $query->expr()->not($query->expr()->eq('a.title', ':title')))
+            ->setParameter('title', 'NA')
+        ;
+
+        $this->translationListener->setTranslatableLocale('en');
+        $this->translationListener->setDefaultLocale('en');
+        $this->translationListener->setTranslationFallback(true);
+        $query = $query->getQuery();
+        $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, self::TREE_WALKER_TRANSLATION);
+
+        $count = 0;
+        str_replace("locale = 'en'", '', $query->getSql(), $count);
+        $this->assertEquals(2, $count);
+    }
+
     public function testIssue109()
     public function testIssue109()
     {
     {
         $this->populateIssue109();
         $this->populateIssue109();