ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGeneratorInterface::generateJoinAlias PHP Method

generateJoinAlias() public method

Generates a cacheable alias for DQL join.
public generateJoinAlias ( string $association ) : string
$association string
return string
    public function generateJoinAlias(string $association) : string;

Usage Example

 /**
  * Joins relations to eager load.
  *
  * @param QueryBuilder                $queryBuilder
  * @param QueryNameGeneratorInterface $queryNameGenerator
  * @param string                      $resourceClass
  * @param bool                        $forceEager
  * @param string                      $parentAlias
  * @param array                       $propertyMetadataOptions
  * @param bool                        $wasLeftJoin             if the relation containing the new one had a left join, we have to force the new one to left join too
  * @param int                         $joinCount               the number of joins
  *
  * @throws RuntimeException when the max number of joins has been reached
  */
 private function joinRelations(QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, bool $forceEager, string $parentAlias, array $propertyMetadataOptions = [], bool $wasLeftJoin = false, int &$joinCount = 0)
 {
     if ($joinCount > $this->maxJoins) {
         throw new RuntimeException('The total number of joined relations has exceeded the specified maximum. Raise the limit if necessary.');
     }
     $entityManager = $queryBuilder->getEntityManager();
     $classMetadata = $entityManager->getClassMetadata($resourceClass);
     foreach ($classMetadata->associationMappings as $association => $mapping) {
         try {
             $propertyMetadata = $this->propertyMetadataFactory->create($resourceClass, $association, $propertyMetadataOptions);
         } catch (PropertyNotFoundException $propertyNotFoundException) {
             //skip properties not found
             continue;
         } catch (ResourceClassNotFoundException $resourceClassNotFoundException) {
             //skip associations that are not resource classes
             continue;
         }
         if (false === $forceEager && ClassMetadataInfo::FETCH_EAGER !== $mapping['fetch']) {
             continue;
         }
         if (false === $propertyMetadata->isReadableLink() || false === $propertyMetadata->isReadable()) {
             continue;
         }
         $isNullable = $mapping['joinColumns'][0]['nullable'] ?? true;
         if (false !== $wasLeftJoin || true === $isNullable) {
             $method = 'leftJoin';
         } else {
             $method = 'innerJoin';
         }
         $associationAlias = $queryNameGenerator->generateJoinAlias($association);
         $queryBuilder->{$method}(sprintf('%s.%s', $parentAlias, $association), $associationAlias);
         ++$joinCount;
         try {
             $this->addSelect($queryBuilder, $mapping['targetEntity'], $associationAlias, $propertyMetadataOptions);
         } catch (ResourceClassNotFoundException $resourceClassNotFoundException) {
             continue;
         }
         $this->joinRelations($queryBuilder, $queryNameGenerator, $mapping['targetEntity'], $forceEager, $associationAlias, $propertyMetadataOptions, $method === 'leftJoin', $joinCount);
     }
 }
All Usage Examples Of ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGeneratorInterface::generateJoinAlias