コード例 #1
0
 /**
  * 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;
 }