Bläddra i källkod

[translatable] small bugfix on odm listener

gediminasm 14 år sedan
förälder
incheckning
ddbfe51320

+ 1 - 1
lib/Gedmo/Sluggable/ODM/MongoDB/SluggableListener.php

@@ -88,7 +88,7 @@ class SluggableListener extends AbstractSluggableListener
             $qb->field($meta->identifier)->notEqual($identifier);
         }
         $qb->where("function() {
-            return this.{$config['slug']}.indexOf('{$preferedSlug}') == 0;
+            return this.{$config['slug']}.indexOf('{$preferedSlug}') === 0;
         }");
         $q = $qb->getQuery();
         $q->setHydrate(false);

+ 5 - 3
lib/Gedmo/Translatable/ODM/MongoDB/TranslationListener.php

@@ -12,10 +12,10 @@ use Doctrine\ODM\MongoDB\Events,
  * loading of translations for documents.
  * 
  * This behavior can inpact the performance of your application
- * since it does an additional query for each field to translate.
+ * since it does an additional query for fields to be translated.
  * 
  * Nevertheless the annotation metadata is properly cached and
- * it is not a big overhead to lookup all entity annotations since
+ * it is not a big overhead to lookup all document annotations since
  * the caching is activated for metadata
  * 
  * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
@@ -165,7 +165,8 @@ class TranslationListener extends AbstractTranslationListener
      */
     protected function findTranslation($om, $objectId, $objectClass, $locale, $field)
     {
-        $qb = $om->createQueryBuilder($objectClass);
+        $translationClass = $this->getTranslationClass($objectClass);
+        $qb = $om->createQueryBuilder($translationClass);
         $q = $qb->field('foreignKey')->equals($objectId)
             ->field('locale')->equals($locale)
             ->field('field')->equals($field)
@@ -176,6 +177,7 @@ class TranslationListener extends AbstractTranslationListener
         if ($result instanceof Cursor) {
             $result = current($result->toArray());
         }
+        $q->setHydrate(false);
         return $result;
     }
     

+ 11 - 0
tests/Gedmo/Translatable/TranslatableDocumentTest.php

@@ -128,6 +128,17 @@ class TranslatableDocumentTest extends \PHPUnit_Framework_TestCase
         $this->assertEquals('Code EN', $article->getCode());
         $this->assertEquals('title-en-code-en', $article->getSlug());
         
+        // test translation update
+        $article->setTitle('Title EN Updated');
+        $article->setCode('Code EN Updated');
+        $this->dm->persist($article);
+        $this->dm->flush();
+        $this->dm->clear();
+        
+        $article = $repo->find($this->articleId);
+        $this->assertEquals('Title EN Updated', $article->getTitle());
+        $this->assertEquals('Code EN Updated', $article->getCode());
+        
         // test removal of translations
         $this->dm->remove($article);
         $this->dm->flush();