mapManyToOne() public method

public mapManyToOne ( $mapping, ClassMetadata $inherited = null )
$inherited ClassMetadata
 /**
  * Adds inherited fields to the subclass mapping.
  *
  * @param ClassMetadata $subClass
  * @param ClassMetadata $parentClass
  */
 private function addInheritedFields(ClassMetadata $subClass, ClassMetadata $parentClass)
 {
     foreach ($parentClass->fieldMappings as $fieldName) {
         $subClass->mapField($parentClass->mappings[$fieldName], $parentClass);
     }
     foreach ($parentClass->referenceMappings as $fieldName) {
         $mapping = $parentClass->mappings[$fieldName];
         if ($mapping['type'] == ClassMetadata::MANY_TO_ONE) {
             $subClass->mapManyToOne($mapping, $parentClass);
         } else {
             $subClass->mapManyToMany($mapping, $parentClass);
         }
     }
     foreach ($parentClass->childMappings as $fieldName) {
         $mapping = $parentClass->mappings[$fieldName];
         $subClass->mapChild($mapping, $parentClass);
     }
     foreach ($parentClass->childrenMappings as $fieldName) {
         $subClass->mapChildren($parentClass->mappings[$fieldName], $parentClass);
     }
     foreach ($parentClass->referrersMappings as $fieldName) {
         $subClass->mapReferrers($parentClass->mappings[$fieldName], $parentClass);
     }
     if ($parentClass->identifier) {
         $subClass->mapId($parentClass->mappings[$parentClass->identifier], $parentClass);
     }
     if ($parentClass->node) {
         $subClass->mapNode($parentClass->mappings[$parentClass->node], $parentClass);
     }
     if ($parentClass->nodename) {
         $subClass->mapNodename($parentClass->mappings[$parentClass->nodename], $parentClass);
     }
     if ($parentClass->parentMapping) {
         $subClass->mapParentDocument($parentClass->mappings[$parentClass->parentMapping], $parentClass);
     }
     if ($parentClass->localeMapping) {
         $subClass->mapLocale($parentClass->mappings[$parentClass->localeMapping], $parentClass);
     }
     if ($parentClass->versionNameField) {
         $subClass->mapVersionName($parentClass->mappings[$parentClass->versionNameField], $parentClass);
     }
     if ($parentClass->versionCreatedField) {
         $subClass->mapVersionCreated($parentClass->mappings[$parentClass->versionCreatedField], $parentClass);
     }
     if ($parentClass->lifecycleCallbacks) {
         $subClass->mapLifecycleCallbacks($parentClass->lifecycleCallbacks);
     }
     $subClass->setReferenceable($parentClass->referenceable);
     // Versionable defaults to false - only set on child class if it is non-false
     if ($parentClass->versionable) {
         $subClass->setVersioned($parentClass->versionable);
     }
     $subClass->setTranslator($parentClass->translator);
     $subClass->setNodeType($parentClass->nodeType);
     $subClass->setCustomRepositoryClassName($parentClass->customRepositoryClassName);
 }
Beispiel #2
0
 /**
  * @param ClassMetadata $cm
  * @depends testClassName
  */
 public function testMapAssociationManyToOne($cm)
 {
     $cm->mapManyToOne(array('fieldName' => 'address', 'targetDocument' => 'Doctrine\\Tests\\ODM\\PHPCR\\Mapping\\Address'));
     $this->assertTrue(isset($cm->associationsMappings['address']), "No 'address' in associations map.");
     $this->assertEquals(array('fieldName' => 'address', 'targetDocument' => 'Doctrine\\Tests\\ODM\\PHPCR\\Mapping\\Address', 'sourceDocument' => 'Doctrine\\Tests\\ODM\\PHPCR\\Mapping\\Person', 'type' => ClassMetadata::MANY_TO_ONE), $cm->associationsMappings['address']);
     return $cm;
 }
 public function testClassMetadataInstanceSerialization()
 {
     $cm = new ClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsUser');
     $cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
     // Test initial state
     $this->assertTrue(count($cm->getReflectionProperties()) == 0);
     $this->assertInstanceOf('ReflectionClass', $cm->reflClass);
     $this->assertEquals('Doctrine\\Tests\\Models\\CMS\\CmsUser', $cm->name);
     $this->assertEquals(array(), $cm->parentClasses);
     $this->assertEquals(0, count($cm->referenceMappings));
     // Customize state
     $cm->setParentClasses(array("UserParent"));
     $cm->setCustomRepositoryClassName("CmsUserRepository");
     $cm->setNodeType('foo:bar');
     $cm->mapManyToOne(array('fieldName' => 'address', 'targetDocument' => 'CmsAddress', 'mappedBy' => 'foo'));
     $this->assertEquals(1, count($cm->referenceMappings));
     $serialized = serialize($cm);
     /** @var ClassMetadata $cm */
     $cm = unserialize($serialized);
     $cm->wakeupReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
     // Check state
     $this->assertTrue(count($cm->getReflectionProperties()) > 0);
     $this->assertEquals('Doctrine\\Tests\\Models\\CMS', $cm->namespace);
     $this->assertInstanceOf('ReflectionClass', $cm->reflClass);
     $this->assertEquals('Doctrine\\Tests\\Models\\CMS\\CmsUser', $cm->name);
     $this->assertEquals(array('UserParent'), $cm->parentClasses);
     $this->assertEquals('Doctrine\\Tests\\Models\\CMS\\CmsUserRepository', $cm->customRepositoryClassName);
     $this->assertEquals('foo:bar', $cm->getNodeType());
     $this->assertEquals(ClassMetadata::MANY_TO_ONE, $cm->getTypeOfField('address'));
     $this->assertEquals(1, count($cm->referenceMappings));
     $this->assertTrue($cm->hasAssociation('address'));
     $this->assertEquals('Doctrine\\Tests\\Models\\CMS\\CmsAddress', $cm->getAssociationTargetClass('address'));
 }