Skip to content
This repository

make mappings & inheritance work + corresponding unit test #105

Closed
wants to merge 1 commit into from

3 participants

Johannes Stark David Buchmann Lukas Kahwe Smith
Johannes Stark

not so sure about that, especially what i did in the ClassMetadataFactory

is this the right approach?

David Buchmann
Collaborator

thanks a lot for looking into this.

unfortunately your fix does not work for me yet. don't we need to remove this check as well?
https://github.com/doctrine/phpcr-odm/blob/master/lib/Doctrine/ODM/PHPCR/Mapping/Driver/AnnotationDriver.php#L98

even if i comment it out, i still get an exception with the sandbox fixtures on persisting MultilangLanguageSelectRoute which extends Route: Undefined index: routeContent in /home/david/liip/symfony-cmf/cmf-sandbox/vendor/symfony-cmf/vendor/doctrine-phpcr-odm/lib/Doctrine/ODM/PHPCR/UnitOfWork.php line 539

can you try to run the fixture loading in the sandbox? (you need to manually set vendor/symfony-cmf/vendor/doctrine-phpcr-odm to your fork)

David Buchmann
Collaborator
Johannes Stark

i think we should continue work with lukas' fix
376a15a

Johannes Stark starkj closed this February 16, 2012
Lukas Kahwe Smith
Collaborator

uhm .. i wasnt even trying to fix this issue .. kinda surprised its fixed .. so i fear it might just be a bug with annotation handling and the issue still exists for xml/yaml

Lukas Kahwe Smith
Collaborator

my bad .. i misunderstood .. so the issue is not yet fixed. but we have a failing test

Lukas Kahwe Smith
Collaborator

ok should work now 115f196

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

Showing 1 unique commit by 1 author.

Feb 14, 2012
Johannes Stark make mappings & inheritance work + corresponding unit test 8aa0f06
This page is out of date. Refresh to see the latest.
23  lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadata.php
@@ -564,16 +564,19 @@ protected function validateAndCompleteFieldMapping($mapping, $isField = true)
564 564
             $mapping['name'] = $mapping['fieldName'];
565 565
         }
566 566
 
567  
-        if (isset($this->fieldMappings[$mapping['fieldName']])
568  
-            || ($this->node == $mapping['fieldName'])
569  
-            || ($this->nodename == $mapping['fieldName'])
570  
-            || ($this->parentMapping == $mapping['fieldName'])
571  
-            || ($this->versionNameField == $mapping['fieldName'])
572  
-            || ($this->versionCreatedField == $mapping['fieldName'])
573  
-            || isset($this->associationsMappings[$mapping['fieldName']])
574  
-            || isset($this->childMappings[$mapping['fieldName']])
575  
-            || isset($this->childrenMappings[$mapping['fieldName']])
576  
-            || isset($this->referrersMappings[$mapping['fieldName']])
  567
+        if ((isset($this->fieldMappings[$mapping['fieldName']])
  568
+              || ($this->node == $mapping['fieldName'])
  569
+              || ($this->nodename == $mapping['fieldName'])
  570
+              || ($this->parentMapping == $mapping['fieldName'])
  571
+              || ($this->versionNameField == $mapping['fieldName'])
  572
+              || ($this->versionCreatedField == $mapping['fieldName'])
  573
+              || isset($this->associationsMappings[$mapping['fieldName']])
  574
+              || isset($this->childMappings[$mapping['fieldName']])
  575
+              || isset($this->childrenMappings[$mapping['fieldName']])
  576
+              || isset($this->referrersMappings[$mapping['fieldName']])
  577
+            )
  578
+            && !isset($this->inheritedFields[$mapping['fieldName']])
  579
+            && !isset($this->declaredFields[$mapping['fieldName']])
577 580
         ) {
578 581
             throw MappingException::duplicateFieldMapping($this->name, $mapping['fieldName']);
579 582
         }
4  lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php
@@ -191,7 +191,11 @@ private function registerParentOnField(ClassMetadata $subClass, ClassMetadata $p
191 191
         if (!$parentClass->isDeclaredField($fieldName)) {
192 192
             $subClass->setDeclaredInherited($fieldName, $parentClass->name);
193 193
         }
  194
+        if ($parentClass->isInheritedField($fieldName)) {
  195
+            $subClass->setDeclaredInherited($fieldName, $parentClass->name);
  196
+        }
194 197
     }
  198
+    
195 199
     /**
196 200
      * {@inheritdoc}
197 201
      */
46  tests/Doctrine/Tests/ODM/PHPCR/Functional/Mapping/AnnotationMappingTest.php
@@ -4,7 +4,8 @@
4 4
 
5 5
 use Doctrine\ODM\PHPCR\Id\RepositoryIdInterface,
6 6
     Doctrine\ODM\PHPCR\DocumentRepository,
7  
-    Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;
  7
+    Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM,
  8
+    Doctrine\ODM\PHPCR\Translation\LocaleChooser\LocaleChooser;
8 9
 
9 10
 /**
10 11
  * @group functional
@@ -39,6 +40,35 @@ public function testSecondLevelInheritance()
39 40
         $this->dm->persist($second);
40 41
     }
41 42
 
  43
+    public function testSecoundLevelOverwrite()
  44
+    {
  45
+
  46
+        $localePrefs = array(
  47
+            'en' => array('en', 'de'),
  48
+            'de' => array('de', 'en'),
  49
+        );
  50
+
  51
+        $this->dm->setLocaleChooserStrategy(new LocaleChooser($localePrefs, 'en'));
  52
+
  53
+        $secondTrans = new SecondLevelOverwrite();
  54
+        $secondTrans->id = '/functional/secondTrans';
  55
+        $secondTrans->username = 'german';
  56
+        $this->dm->persist($secondTrans);
  57
+        $this->dm->bindTranslation($secondTrans, 'de');
  58
+        $secondTrans->username = 'english';
  59
+        $this->dm->bindTranslation($secondTrans, 'en');
  60
+
  61
+        $this->dm->flush();
  62
+
  63
+        $tmpDocDe = $this->dm->findTranslation(null, '/functional/secondTrans', 'de');
  64
+
  65
+        $this->assertEquals($tmpDocDe->username, 'german');
  66
+
  67
+        $tmpDocEn = $this->dm->findTranslation(null, '/functional/secondTrans', 'en');
  68
+
  69
+        $this->assertEquals($tmpDocEn->username, 'english');
  70
+    }
  71
+
42 72
     // TODO comprehensive test for all possible mapped fields in an abstract test, trying to persist and check if properly set
43 73
     // then dm->clear and check if still properly set.
44 74
 
@@ -75,3 +105,17 @@ class ExtendingClass extends Testclass
75 105
 class SecondLevel extends ExtendingClass
76 106
 {
77 107
 }
  108
+
  109
+/**
  110
+ * @PHPCRODM\Document(translator="attribute")
  111
+ */
  112
+class SecondLevelOverwrite extends ExtendingClass
  113
+{
  114
+    /**
  115
+     * @PHPCRODM\Locale
  116
+     */
  117
+    public $locale;
  118
+
  119
+    /** @PHPCRODM\String(translated=true) */
  120
+    public $username;
  121
+}
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.