当前位置: 首页>>代码示例>>PHP>>正文


PHP ClassMetadata::mapOneToOne方法代码示例

本文整理汇总了PHP中Doctrine\ORM\Mapping\ClassMetadata::mapOneToOne方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassMetadata::mapOneToOne方法的具体用法?PHP ClassMetadata::mapOneToOne怎么用?PHP ClassMetadata::mapOneToOne使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Doctrine\ORM\Mapping\ClassMetadata的用法示例。


在下文中一共展示了ClassMetadata::mapOneToOne方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testClassMetadataInstanceSerialization

 public function testClassMetadataInstanceSerialization()
 {
     $cm = new ClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsUser');
     // Test initial state
     $this->assertTrue(count($cm->getReflectionProperties()) == 0);
     $this->assertTrue($cm->reflClass instanceof \ReflectionClass);
     $this->assertEquals('Doctrine\\Tests\\Models\\CMS\\CmsUser', $cm->name);
     $this->assertEquals('Doctrine\\Tests\\Models\\CMS\\CmsUser', $cm->rootEntityName);
     $this->assertEquals(array(), $cm->subClasses);
     $this->assertEquals(array(), $cm->parentClasses);
     // Customize state
     $cm->setSubclasses(array("One", "Two", "Three"));
     $cm->setParentClasses(array("UserParent"));
     $cm->setCustomRepositoryClass("UserRepository");
     $cm->setDiscriminatorColumn(array('name' => 'disc', 'type' => 'integer'));
     $cm->mapOneToOne(array('fieldName' => 'phonenumbers', 'targetEntity' => 'Bar', 'mappedBy' => 'foo'));
     $this->assertTrue($cm->getAssociationMapping('phonenumbers') instanceof \Doctrine\ORM\Mapping\OneToOneMapping);
     $this->assertEquals(1, count($cm->associationMappings));
     $serialized = serialize($cm);
     $cm = unserialize($serialized);
     // Check state
     $this->assertTrue(count($cm->getReflectionProperties()) > 0);
     $this->assertTrue($cm->reflClass instanceof \ReflectionClass);
     $this->assertEquals('Doctrine\\Tests\\Models\\CMS\\CmsUser', $cm->name);
     $this->assertEquals('UserParent', $cm->rootEntityName);
     $this->assertEquals(array('One', 'Two', 'Three'), $cm->subClasses);
     $this->assertEquals(array('UserParent'), $cm->parentClasses);
     $this->assertEquals('UserRepository', $cm->getCustomRepositoryClass());
     $this->assertEquals(array('name' => 'disc', 'type' => 'integer'), $cm->discriminatorColumn);
     $this->assertTrue($cm->getAssociationMapping('phonenumbers') instanceof \Doctrine\ORM\Mapping\OneToOneMapping);
     $this->assertEquals(1, count($cm->associationMappings));
     $oneOneMapping = $cm->getAssociationMapping('phonenumbers');
     $this->assertEquals('phonenumbers', $oneOneMapping->getSourceFieldName());
     $this->assertEquals('Doctrine\\Tests\\Models\\CMS\\Bar', $oneOneMapping->getTargetEntityName());
 }
开发者ID:jackbravo,项目名称:doctrine,代码行数:35,代码来源:ClassMetadataTest.php

示例2: testGetMetadataForSingleClass

 public function testGetMetadataForSingleClass()
 {
     $mockPlatform = new DatabasePlatformMock();
     $mockDriver = new MetadataDriverMock();
     $mockPlatform->setPrefersSequences(true);
     $mockPlatform->setPrefersIdentityColumns(false);
     // Self-made metadata
     $cm1 = new ClassMetadata('Doctrine\\Tests\\ORM\\Mapping\\TestEntity1');
     // Add a mapped field
     $cm1->mapField(array('fieldName' => 'name', 'type' => 'varchar'));
     // Add a mapped field
     $cm1->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true));
     // and a mapped association
     $cm1->mapOneToOne(array('fieldName' => 'other', 'targetEntity' => 'Other', 'mappedBy' => 'this'));
     // and an id generator type
     $cm1->setIdGeneratorType('auto');
     // SUT
     $cmf = new ClassMetadataFactoryTestSubject($mockDriver, $mockPlatform);
     $cmf->setMetadataForClass('Doctrine\\Tests\\ORM\\Mapping\\TestEntity1', $cm1);
     // Prechecks
     $this->assertEquals(array(), $cm1->parentClasses);
     $this->assertEquals('none', $cm1->inheritanceType);
     $this->assertTrue($cm1->hasField('name'));
     $this->assertEquals(1, count($cm1->associationMappings));
     $this->assertEquals('auto', $cm1->generatorType);
     // Go
     $cm1 = $cmf->getMetadataFor('Doctrine\\Tests\\ORM\\Mapping\\TestEntity1');
     $this->assertEquals(array(), $cm1->parentClasses);
     $this->assertTrue($cm1->hasField('name'));
     $this->assertEquals('sequence', $cm1->generatorType);
 }
开发者ID:jackbravo,项目名称:doctrine,代码行数:31,代码来源:ClassMetadataFactoryTest.php

示例3: testGetMetadataForSingleClass

 public function testGetMetadataForSingleClass()
 {
     $mockDriver = new MetadataDriverMock();
     $entityManager = $this->_createEntityManager($mockDriver);
     $conn = $entityManager->getConnection();
     $mockPlatform = $conn->getDatabasePlatform();
     $mockPlatform->setPrefersSequences(true);
     $mockPlatform->setPrefersIdentityColumns(false);
     // Self-made metadata
     $cm1 = new ClassMetadata('Doctrine\\Tests\\ORM\\Mapping\\TestEntity1');
     $cm1->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
     $cm1->setPrimaryTable(array('name' => '`group`'));
     // Add a mapped field
     $cm1->mapField(array('fieldName' => 'name', 'type' => 'varchar'));
     // Add a mapped field
     $cm1->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true));
     // and a mapped association
     $cm1->mapOneToOne(array('fieldName' => 'other', 'targetEntity' => 'TestEntity1', 'mappedBy' => 'this'));
     // and an association on the owning side
     $joinColumns = array(array('name' => 'other_id', 'referencedColumnName' => 'id'));
     $cm1->mapOneToOne(array('fieldName' => 'association', 'targetEntity' => 'TestEntity1', 'joinColumns' => $joinColumns));
     // and an id generator type
     $cm1->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_AUTO);
     // SUT
     $cmf = new \Doctrine\ORM\Mapping\ClassMetadataFactory();
     $cmf->setEntityManager($entityManager);
     $cmf->setMetadataFor('Doctrine\\Tests\\ORM\\Mapping\\TestEntity1', $cm1);
     // Prechecks
     $this->assertEquals(array(), $cm1->parentClasses);
     $this->assertEquals(ClassMetadata::INHERITANCE_TYPE_NONE, $cm1->inheritanceType);
     $this->assertTrue($cm1->hasField('name'));
     $this->assertEquals(2, count($cm1->associationMappings));
     $this->assertEquals(ClassMetadata::GENERATOR_TYPE_AUTO, $cm1->generatorType);
     $this->assertEquals('group', $cm1->table['name']);
     // Go
     $cmMap1 = $cmf->getMetadataFor('Doctrine\\Tests\\ORM\\Mapping\\TestEntity1');
     $this->assertSame($cm1, $cmMap1);
     $this->assertEquals('group', $cmMap1->table['name']);
     $this->assertTrue($cmMap1->table['quoted']);
     $this->assertEquals(array(), $cmMap1->parentClasses);
     $this->assertTrue($cmMap1->hasField('name'));
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:42,代码来源:ClassMetadataFactoryTest.php

示例4: testAddNamedNativeQueryResultSetMapping

 /**
  * @group DDC-1663
  */
 public function testAddNamedNativeQueryResultSetMapping()
 {
     $cm = new ClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsUser');
     $cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
     $cm->mapOneToOne(array('fieldName' => 'email', 'targetEntity' => 'Doctrine\\Tests\\Models\\CMS\\CmsEmail', 'cascade' => array('persist'), 'inversedBy' => 'user', 'orphanRemoval' => false, 'joinColumns' => array(array('nullable' => true, 'referencedColumnName' => 'id'))));
     $cm->addNamedNativeQuery(array('name' => 'find-all', 'query' => 'SELECT u.id AS user_id, e.id AS email_id, u.name, e.email, u.id + e.id AS scalarColumn FROM cms_users u INNER JOIN cms_emails e ON e.id = u.email_id', 'resultSetMapping' => 'find-all'));
     $cm->addSqlResultSetMapping(array('name' => 'find-all', 'entities' => array(array('entityClass' => '__CLASS__', 'fields' => array(array('name' => 'id', 'column' => 'user_id'), array('name' => 'name', 'column' => 'name'))), array('entityClass' => 'CmsEmail', 'fields' => array(array('name' => 'id', 'column' => 'email_id'), array('name' => 'email', 'column' => 'email')))), 'columns' => array(array('name' => 'scalarColumn'))));
     $queryMapping = $cm->getNamedNativeQuery('find-all');
     $rsm = new \Doctrine\ORM\Query\ResultSetMappingBuilder($this->_em);
     $rsm->addNamedNativeQueryMapping($cm, $queryMapping);
     $this->assertEquals('scalarColumn', $rsm->getScalarAlias('scalarColumn'));
     $this->assertEquals('c0', $rsm->getEntityAlias('user_id'));
     $this->assertEquals('c0', $rsm->getEntityAlias('name'));
     $this->assertEquals('Doctrine\\Tests\\Models\\CMS\\CmsUser', $rsm->getClassName('c0'));
     $this->assertEquals('Doctrine\\Tests\\Models\\CMS\\CmsUser', $rsm->getDeclaringClass('name'));
     $this->assertEquals('Doctrine\\Tests\\Models\\CMS\\CmsUser', $rsm->getDeclaringClass('user_id'));
     $this->assertEquals('c1', $rsm->getEntityAlias('email_id'));
     $this->assertEquals('c1', $rsm->getEntityAlias('email'));
     $this->assertEquals('Doctrine\\Tests\\Models\\CMS\\CmsEmail', $rsm->getClassName('c1'));
     $this->assertEquals('Doctrine\\Tests\\Models\\CMS\\CmsEmail', $rsm->getDeclaringClass('email'));
     $this->assertEquals('Doctrine\\Tests\\Models\\CMS\\CmsEmail', $rsm->getDeclaringClass('email_id'));
 }
开发者ID:pnaq57,项目名称:zf2demo,代码行数:25,代码来源:ResultSetMappingTest.php

示例5: testInverseIdentifierAssocation

 /**
  * @group DDC-117
  */
 public function testInverseIdentifierAssocation()
 {
     $cm = new ClassMetadata('Doctrine\\Tests\\Models\\DDC117\\DDC117ArticleDetails');
     $this->setExpectedException('Doctrine\\ORM\\Mapping\\MappingException', 'An inverse association is not allowed to be identifier in');
     $cm->mapOneToOne(array('fieldName' => 'article', 'id' => true, 'mappedBy' => 'details', 'targetEntity' => 'Doctrine\\Tests\\Models\\DDC117\\DDC117Article', 'joinColumns' => array()));
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:9,代码来源:ClassMetadataTest.php

示例6: testDefaultJoinColumnName

 public function testDefaultJoinColumnName()
 {
     $cm = new ClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsAddress');
     // this is really dirty, but it's the simpliest way to test whether
     // joinColumn's name will be automatically set to user_id
     $cm->mapOneToOne(array('fieldName' => 'user', 'targetEntity' => 'CmsUser', 'joinColumns' => array(array('referencedColumnName' => 'id'))));
     $this->assertEquals('user_id', $cm->associationMappings['user']['joinColumns'][0]['name']);
     $cm = new ClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsAddress');
     $cm->mapManyToMany(array('fieldName' => 'user', 'targetEntity' => 'CmsUser', 'inversedBy' => 'users', 'joinTable' => array('name' => 'user_CmsUser', 'joinColumns' => array(array('referencedColumnName' => 'id')), 'inverseJoinColumns' => array(array('referencedColumnName' => 'id')))));
     $this->assertEquals('cmsaddress_id', $cm->associationMappings['user']['joinTable']['joinColumns'][0]['name']);
     $this->assertEquals('cmsuser_id', $cm->associationMappings['user']['joinTable']['inverseJoinColumns'][0]['name']);
 }
开发者ID:jsuggs,项目名称:BBM_old,代码行数:12,代码来源:ClassMetadataTest.php

示例7: _createValidClassMetadata

 /**
  * @param string $class
  * @return ClassMetadata
  */
 protected function _createValidClassMetadata()
 {
     // Self-made metadata
     $cm1 = new ClassMetadata('Doctrine\\Tests\\ORM\\Mapping\\TestEntity1');
     $cm1->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
     $cm1->setPrimaryTable(array('name' => '`group`'));
     // Add a mapped field
     $cm1->mapField(array('fieldName' => 'name', 'type' => 'varchar'));
     // Add a mapped field
     $cm1->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true));
     // and a mapped association
     $cm1->mapOneToOne(array('fieldName' => 'other', 'targetEntity' => 'TestEntity1', 'mappedBy' => 'this'));
     // and an association on the owning side
     $joinColumns = array(array('name' => 'other_id', 'referencedColumnName' => 'id'));
     $cm1->mapOneToOne(array('fieldName' => 'association', 'targetEntity' => 'TestEntity1', 'joinColumns' => $joinColumns));
     // and an id generator type
     $cm1->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_AUTO);
     return $cm1;
 }
开发者ID:naumangcu,项目名称:doctrine2,代码行数:23,代码来源:ClassMetadataFactoryTest.php

示例8: loadMetadataForClass

 /**
  * Loads the metadata for the specified class into the provided container.
  */
 public function loadMetadataForClass($className, ClassMetadata $metadata)
 {
     $annotClass = new \Addendum\ReflectionAnnotatedClass($className);
     // Evaluate DoctrineEntity annotation
     if (($entityAnnot = $annotClass->getAnnotation('DoctrineEntity')) === false) {
         throw DoctrineException::updateMe("{$className} is no entity.");
     }
     $metadata->setCustomRepositoryClass($entityAnnot->repositoryClass);
     // Evaluate DoctrineTable annotation
     if ($tableAnnot = $annotClass->getAnnotation('DoctrineTable')) {
         $metadata->setPrimaryTable(array('name' => $tableAnnot->name, 'schema' => $tableAnnot->schema, 'catalog' => $tableAnnot->catalog));
     }
     // Evaluate DoctrineInheritanceType annotation
     if ($inheritanceTypeAnnot = $annotClass->getAnnotation('DoctrineInheritanceType')) {
         $metadata->setInheritanceType($inheritanceTypeAnnot->value);
     }
     // Evaluate DoctrineDiscriminatorColumn annotation
     if ($discrColumnAnnot = $annotClass->getAnnotation('DoctrineDiscriminatorColumn')) {
         $metadata->setDiscriminatorColumn(array('name' => $discrColumnAnnot->name, 'type' => $discrColumnAnnot->type, 'length' => $discrColumnAnnot->length));
     }
     // Evaluate DoctrineDiscriminatorMap annotation
     if ($discrValueAnnot = $annotClass->getAnnotation('DoctrineDiscriminatorValue')) {
         $metadata->setDiscriminatorValue($discrValueAnnot->value);
     }
     // Evaluate DoctrineSubClasses annotation
     if ($subClassesAnnot = $annotClass->getAnnotation('DoctrineSubClasses')) {
         $metadata->setSubclasses($subClassesAnnot->value);
     }
     // Evaluate DoctrineChangeTrackingPolicy annotation
     if ($changeTrackingAnnot = $annotClass->getAnnotation('DoctrineChangeTrackingPolicy')) {
         $metadata->setChangeTrackingPolicy($changeTrackingAnnot->value);
     }
     // Evaluate annotations on properties/fields
     foreach ($annotClass->getProperties() as $property) {
         if ($metadata->hasField($property->getName())) {
             continue;
         }
         $mapping = array();
         $mapping['fieldName'] = $property->getName();
         // Check for DoctrineJoinColummn/DoctrineJoinColumns annotations
         $joinColumns = array();
         if ($joinColumnAnnot = $property->getAnnotation('DoctrineJoinColumn')) {
             $joinColumns[] = array('name' => $joinColumnAnnot->name, 'referencedColumnName' => $joinColumnAnnot->referencedColumnName, 'unique' => $joinColumnAnnot->unique, 'nullable' => $joinColumnAnnot->nullable, 'onDelete' => $joinColumnAnnot->onDelete, 'onUpdate' => $joinColumnAnnot->onUpdate);
         } else {
             if ($joinColumnsAnnot = $property->getAnnotation('DoctrineJoinColumns')) {
                 $joinColumns = $joinColumnsAnnot->value;
             }
         }
         // Field can only be annotated with one of: DoctrineColumn,
         // DoctrineOneToOne, DoctrineOneToMany, DoctrineManyToOne, DoctrineManyToMany
         if ($columnAnnot = $property->getAnnotation('DoctrineColumn')) {
             if ($columnAnnot->type == null) {
                 throw DoctrineException::updateMe("Missing type on property " . $property->getName());
             }
             $mapping['type'] = $columnAnnot->type;
             $mapping['length'] = $columnAnnot->length;
             $mapping['nullable'] = $columnAnnot->nullable;
             if ($idAnnot = $property->getAnnotation('DoctrineId')) {
                 $mapping['id'] = true;
             }
             if ($generatedValueAnnot = $property->getAnnotation('DoctrineGeneratedValue')) {
                 $metadata->setIdGeneratorType($generatedValueAnnot->strategy);
             }
             $metadata->mapField($mapping);
             // Check for SequenceGenerator/TableGenerator definition
             if ($seqGeneratorAnnot = $property->getAnnotation('DoctrineSequenceGenerator')) {
                 $metadata->setSequenceGeneratorDefinition(array('sequenceName' => $seqGeneratorAnnot->sequenceName, 'allocationSize' => $seqGeneratorAnnot->allocationSize, 'initialValue' => $seqGeneratorAnnot->initialValue));
             } else {
                 if ($tblGeneratorAnnot = $property->getAnnotation('DoctrineTableGenerator')) {
                     throw new DoctrineException("DoctrineTableGenerator not yet implemented.");
                 }
             }
         } else {
             if ($oneToOneAnnot = $property->getAnnotation('DoctrineOneToOne')) {
                 $mapping['targetEntity'] = $oneToOneAnnot->targetEntity;
                 $mapping['joinColumns'] = $joinColumns;
                 $mapping['mappedBy'] = $oneToOneAnnot->mappedBy;
                 $mapping['cascade'] = $oneToOneAnnot->cascade;
                 $metadata->mapOneToOne($mapping);
             } else {
                 if ($oneToManyAnnot = $property->getAnnotation('DoctrineOneToMany')) {
                     $mapping['mappedBy'] = $oneToManyAnnot->mappedBy;
                     $mapping['targetEntity'] = $oneToManyAnnot->targetEntity;
                     $mapping['cascade'] = $oneToManyAnnot->cascade;
                     $metadata->mapOneToMany($mapping);
                 } else {
                     if ($manyToOneAnnot = $property->getAnnotation('DoctrineManyToOne')) {
                         $mapping['joinColumns'] = $joinColumns;
                         $mapping['cascade'] = $manyToOneAnnot->cascade;
                         $mapping['targetEntity'] = $manyToOneAnnot->targetEntity;
                         $metadata->mapManyToOne($mapping);
                     } else {
                         if ($manyToManyAnnot = $property->getAnnotation('DoctrineManyToMany')) {
                             $joinTable = array();
                             if ($joinTableAnnot = $property->getAnnotation('DoctrineJoinTable')) {
                                 $joinTable = array('name' => $joinTableAnnot->name, 'schema' => $joinTableAnnot->schema, 'catalog' => $joinTableAnnot->catalog, 'joinColumns' => $joinTableAnnot->joinColumns, 'inverseJoinColumns' => $joinTableAnnot->inverseJoinColumns);
                             }
//.........这里部分代码省略.........
开发者ID:jackbravo,项目名称:doctrine,代码行数:101,代码来源:AnnotationDriver.php

示例9: testDuplicateFieldAndAssocationMapping2_ThrowsException

 public function testDuplicateFieldAndAssocationMapping2_ThrowsException()
 {
     $cm = new ClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsUser');
     $cm->mapOneToOne(array('fieldName' => 'name', 'targetEntity' => 'CmsUser'));
     $this->setExpectedException('Doctrine\\ORM\\Mapping\\MappingException');
     $cm->mapField(array('fieldName' => 'name', 'columnName' => 'name'));
 }
开发者ID:andreia,项目名称:doctrine,代码行数:7,代码来源:ClassMetadataTest.php


注:本文中的Doctrine\ORM\Mapping\ClassMetadata::mapOneToOne方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。