当前位置: 首页>>代码示例>>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;未经允许,请勿转载。