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


PHP ClassMetadataInfo::getAssociationsByTargetClass方法代码示例

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


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

示例1: addNamedNativeQueryResultSetMapping

 /**
  * Adds the result set mapping of the results of native SQL queries to the result set.
  *
  * @param   ClassMetadataInfo $class
  * @param   string $resultSetMappingName
  * @return  ResultSetMappingBuilder
  */
 public function addNamedNativeQueryResultSetMapping(ClassMetadataInfo $class, $resultSetMappingName)
 {
     $counter = 0;
     $resultMapping = $class->getSqlResultSetMapping($resultSetMappingName);
     $rooShortName = $class->reflClass->getShortName();
     $rootAlias = strtolower($rooShortName[0]) . $counter;
     if (isset($resultMapping['entities'])) {
         foreach ($resultMapping['entities'] as $key => $entityMapping) {
             $classMetadata = $this->em->getClassMetadata($entityMapping['entityClass']);
             if ($class->reflClass->name == $classMetadata->reflClass->name) {
                 $this->addEntityResult($classMetadata->name, $rootAlias);
                 $this->addNamedNativeQueryEntityResultMapping($classMetadata, $entityMapping, $rootAlias);
             } else {
                 $shortName = $classMetadata->reflClass->getShortName();
                 $joinAlias = strtolower($shortName[0]) . ++$counter;
                 $associations = $class->getAssociationsByTargetClass($classMetadata->name);
                 foreach ($associations as $relation => $mapping) {
                     $this->addJoinedEntityResult($mapping['targetEntity'], $joinAlias, $rootAlias, $relation);
                     $this->addNamedNativeQueryEntityResultMapping($classMetadata, $entityMapping, $joinAlias);
                 }
             }
         }
     }
     if (isset($resultMapping['columns'])) {
         foreach ($resultMapping['columns'] as $entityMapping) {
             $this->addScalarResult($entityMapping['name'], $entityMapping['name']);
         }
     }
     return $this;
 }
开发者ID:relo-san,项目名称:doctrine2,代码行数:37,代码来源:ResultSetMappingBuilder.php

示例2: setAssociation

 /**
  * Add the parent entity using the doctrine metadata on the target entity
  *
  * @param object            $targetEntity
  * @param object            $parentEntity
  * @param ClassMetadataInfo $targetMetadata
  * @param ClassMetadataInfo $parentMetadata
  *
  * @return void
  */
 private function setAssociation($targetEntity, $parentEntity, ClassMetadataInfo $targetMetadata, ClassMetadataInfo $parentMetadata)
 {
     $associations = $targetMetadata->getAssociationsByTargetClass($parentMetadata->name);
     foreach ($associations as $association) {
         // We can only update association where the targetEntity is the owning side, else doctrine will just
         // discard it.
         if ($association['isOwningSide']) {
             $reflection = $targetMetadata->getReflectionProperty($association['fieldName']);
             $reflection->setAccessible(true);
             $reflection->setValue($targetEntity, $parentEntity);
         }
     }
     if (count($parentMetadata->parentClasses) > 0) {
         $parentMetadata = $this->entityManager->getClassMetadata(current($parentMetadata->parentClasses));
         $this->setAssociation($targetEntity, $parentEntity, $targetMetadata, $parentMetadata);
     }
 }
开发者ID:interactive-solutions,项目名称:zf-behat,代码行数:27,代码来源:EntityFixtureContext.php


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