當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ClassMetadata::mapManyToMany方法代碼示例

本文整理匯總了PHP中Doctrine\ORM\Mapping\ClassMetadata::mapManyToMany方法的典型用法代碼示例。如果您正苦於以下問題:PHP ClassMetadata::mapManyToMany方法的具體用法?PHP ClassMetadata::mapManyToMany怎麽用?PHP ClassMetadata::mapManyToMany使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Doctrine\ORM\Mapping\ClassMetadata的用法示例。


在下文中一共展示了ClassMetadata::mapManyToMany方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testMapManyToManyJoinTableDefaults

 public function testMapManyToManyJoinTableDefaults()
 {
     $cm = new ClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsUser');
     $cm->mapManyToMany(array('fieldName' => 'groups', 'targetEntity' => 'CmsGroup'));
     $assoc = $cm->associationMappings['groups'];
     $this->assertTrue($assoc instanceof \Doctrine\ORM\Mapping\ManyToManyMapping);
     $this->assertEquals(array('name' => 'CmsUser_CmsGroup', 'joinColumns' => array(array('name' => 'CmsUser_id', 'referencedColumnName' => 'id')), 'inverseJoinColumns' => array(array('name' => 'CmsGroup_id', 'referencedColumnName' => 'id'))), $assoc->joinTable);
 }
開發者ID:andreia,項目名稱:doctrine,代碼行數:8,代碼來源:ClassMetadataTest.php

示例2: testPrefixManyToMany

 public function testPrefixManyToMany()
 {
     $em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $subscriber = new TablePrefixSubscriber('yo_');
     $metaClass = new ClassMetadata('Wallabag\\UserBundle\\Entity\\Entry');
     $metaClass->setPrimaryTable(['name' => 'entry']);
     $metaClass->mapManyToMany(['fieldName' => 'tags', 'joinTable' => ['name' => null, 'schema' => null], 'targetEntity' => 'Tag', 'mappedBy' => null, 'inversedBy' => 'entries', 'cascade' => ['persist'], 'indexBy' => null, 'orphanRemoval' => false, 'fetch' => 2]);
     $metaDataEvent = new LoadClassMetadataEventArgs($metaClass, $em);
     $this->assertEquals('entry', $metaDataEvent->getClassMetadata()->getTableName());
     $subscriber->loadClassMetadata($metaDataEvent);
     $this->assertEquals('yo_entry', $metaDataEvent->getClassMetadata()->getTableName());
     $this->assertEquals('yo_entry_tag', $metaDataEvent->getClassMetadata()->associationMappings['tags']['joinTable']['name']);
     $this->assertEquals('yo_entry', $metaDataEvent->getClassMetadata()->getQuotedTableName(new \Doctrine\DBAL\Platforms\MySqlPlatform()));
 }
開發者ID:jjanvier,項目名稱:wallabag,代碼行數:14,代碼來源:TablePrefixSubscriberTest.php

示例3: testIdentifierAssocationManyToMany

 /**
  * @group DDC-117
  */
 public function testIdentifierAssocationManyToMany()
 {
     $cm = new ClassMetadata('Doctrine\\Tests\\Models\\DDC117\\DDC117ArticleDetails');
     $this->setExpectedException('Doctrine\\ORM\\Mapping\\MappingException', 'Many-to-many or one-to-many associations are not allowed to be identifier in');
     $cm->mapManyToMany(array('fieldName' => 'article', 'id' => true, 'targetEntity' => 'Doctrine\\Tests\\Models\\DDC117\\DDC117Article', 'joinColumns' => array()));
 }
開發者ID:dracony,項目名稱:forked-php-orm-benchmark,代碼行數:9,代碼來源:ClassMetadataTest.php

示例4: 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

示例5: setReadedTopicsAssociation

 /**
  * Adds readed topics association mapping to User class
  * 
  * @param ClassMetadata              $classMetadata
  * @param LoadClassMetadataEventArgs $eventArgs
  */
 protected function setReadedTopicsAssociation(ClassMetadata $classMetadata, LoadClassMetadataEventArgs $eventArgs)
 {
     $classMetadata->mapManyToMany(array('fieldName' => 'readedTopics', 'mappedBy' => 'readers', 'targetEntity' => 'Valantir\\ForumBundle\\Entity\\Topic'));
 }
開發者ID:Valantir007,項目名稱:ForumBundle,代碼行數:10,代碼來源:MappingListener.php

示例6: testManyToManySelfReferencingNamingStrategyDefaults

 public function testManyToManySelfReferencingNamingStrategyDefaults()
 {
     $cm = new ClassMetadata('Doctrine\\Tests\\Models\\CustomType\\CustomTypeParent');
     $cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
     $cm->mapManyToMany(array('fieldName' => 'friendsWithMe', 'targetEntity' => 'CustomTypeParent'));
     $this->assertEquals(array('name' => 'customtypeparent_customtypeparent', 'joinColumns' => array(array('name' => 'customtypeparent_source', 'referencedColumnName' => 'id', 'onDelete' => 'CASCADE')), 'inverseJoinColumns' => array(array('name' => 'customtypeparent_target', 'referencedColumnName' => 'id', 'onDelete' => 'CASCADE'))), $cm->associationMappings['friendsWithMe']['joinTable']);
     $this->assertEquals(array('customtypeparent_source', 'customtypeparent_target'), $cm->associationMappings['friendsWithMe']['joinTableColumns']);
     $this->assertEquals(array('customtypeparent_source' => 'id'), $cm->associationMappings['friendsWithMe']['relationToSourceKeyColumns']);
     $this->assertEquals(array('customtypeparent_target' => 'id'), $cm->associationMappings['friendsWithMe']['relationToTargetKeyColumns']);
 }
開發者ID:annProg,項目名稱:yourCMDB,代碼行數:10,代碼來源:ClassMetadataTest.php

示例7: testFullyQualifiedClassNameShouldBeGivenToNamingStrategy

 /**
  * @group DDC-984
  * @group DDC-559
  * @group DDC-1575
  */
 public function testFullyQualifiedClassNameShouldBeGivenToNamingStrategy()
 {
     $namingStrategy = new MyNamespacedNamingStrategy();
     $addressMetadata = new ClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsAddress', $namingStrategy);
     $articleMetadata = new ClassMetadata('DoctrineGlobal_Article', $namingStrategy);
     $routingMetadata = new ClassMetadata('Doctrine\\Tests\\Models\\Routing\\RoutingLeg', $namingStrategy);
     $addressMetadata->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
     $articleMetadata->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
     $routingMetadata->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
     $addressMetadata->mapManyToMany(array('fieldName' => 'user', 'targetEntity' => 'CmsUser'));
     $articleMetadata->mapManyToMany(array('fieldName' => 'author', 'targetEntity' => 'Doctrine\\Tests\\Models\\CMS\\CmsUser'));
     $this->assertEquals('routing_routingleg', $routingMetadata->table['name']);
     $this->assertEquals('cms_cmsaddress_cms_cmsuser', $addressMetadata->associationMappings['user']['joinTable']['name']);
     $this->assertEquals('doctrineglobal_article_cms_cmsuser', $articleMetadata->associationMappings['author']['joinTable']['name']);
 }
開發者ID:davidbui2,項目名稱:doctrine2,代碼行數:20,代碼來源:ClassMetadataTest.php

示例8: testJoinTableMappingDefaults

 /**
  * @group DDC-961
  */
 public function testJoinTableMappingDefaults()
 {
     $cm = new ClassMetadata('DoctrineGlobal_Article');
     $cm->mapManyToMany(array('fieldName' => 'author', 'targetEntity' => 'Doctrine\\Tests\\Models\\CMS\\CmsUser'));
     $this->assertEquals('doctrineglobal_article_cmsuser', $cm->associationMappings['author']['joinTable']['name']);
 }
開發者ID:dracony,項目名稱:forked-php-orm-benchmark,代碼行數:9,代碼來源:ClassMetadataTest.php

示例9: loadMetadataForClass


//.........這裏部分代碼省略.........
     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);
                             }
                             $mapping['joinTable'] = $joinTable;
                             $mapping['targetEntity'] = $manyToManyAnnot->targetEntity;
                             $mapping['mappedBy'] = $manyToManyAnnot->mappedBy;
                             $mapping['cascade'] = $manyToManyAnnot->cascade;
                             $metadata->mapManyToMany($mapping);
                         }
                     }
                 }
             }
         }
     }
 }
開發者ID:jackbravo,項目名稱:doctrine,代碼行數:101,代碼來源:AnnotationDriver.php


注:本文中的Doctrine\ORM\Mapping\ClassMetadata::mapManyToMany方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。