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


PHP SqlWalker::getSQLTableAlias方法代碼示例

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


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

示例1: getSql

 /**
  * @override
  * @todo If the collection being counted is already joined, the SQL can be simpler (more efficient).
  */
 public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
 {
     $platform = $sqlWalker->getEntityManager()->getConnection()->getDatabasePlatform();
     $quoteStrategy = $sqlWalker->getEntityManager()->getConfiguration()->getQuoteStrategy();
     $dqlAlias = $this->collectionPathExpression->identificationVariable;
     $assocField = $this->collectionPathExpression->field;
     $qComp = $sqlWalker->getQueryComponent($dqlAlias);
     $class = $qComp['metadata'];
     $assoc = $class->associationMappings[$assocField];
     $sql = 'SELECT COUNT(*) FROM ';
     if ($assoc['type'] == \Doctrine\ORM\Mapping\ClassMetadata::ONE_TO_MANY) {
         $targetClass = $sqlWalker->getEntityManager()->getClassMetadata($assoc['targetEntity']);
         $targetTableAlias = $sqlWalker->getSQLTableAlias($targetClass->getTableName());
         $sourceTableAlias = $sqlWalker->getSQLTableAlias($class->getTableName(), $dqlAlias);
         $sql .= $quoteStrategy->getTableName($targetClass, $platform) . ' ' . $targetTableAlias . ' WHERE ';
         $owningAssoc = $targetClass->associationMappings[$assoc['mappedBy']];
         $first = true;
         foreach ($owningAssoc['targetToSourceKeyColumns'] as $targetColumn => $sourceColumn) {
             if ($first) {
                 $first = false;
             } else {
                 $sql .= ' AND ';
             }
             $sql .= $targetTableAlias . '.' . $sourceColumn . ' = ' . $sourceTableAlias . '.' . $quoteStrategy->getColumnName($class->fieldNames[$targetColumn], $class, $platform);
         }
     } else {
         // many-to-many
         $targetClass = $sqlWalker->getEntityManager()->getClassMetadata($assoc['targetEntity']);
         $owningAssoc = $assoc['isOwningSide'] ? $assoc : $targetClass->associationMappings[$assoc['mappedBy']];
         $joinTable = $owningAssoc['joinTable'];
         // SQL table aliases
         $joinTableAlias = $sqlWalker->getSQLTableAlias($joinTable['name']);
         $sourceTableAlias = $sqlWalker->getSQLTableAlias($class->getTableName(), $dqlAlias);
         // join to target table
         $sql .= $quoteStrategy->getJoinTableName($owningAssoc, $targetClass, $platform) . ' ' . $joinTableAlias . ' WHERE ';
         $joinColumns = $assoc['isOwningSide'] ? $joinTable['joinColumns'] : $joinTable['inverseJoinColumns'];
         $first = true;
         foreach ($joinColumns as $joinColumn) {
             if ($first) {
                 $first = false;
             } else {
                 $sql .= ' AND ';
             }
             $sourceColumnName = $quoteStrategy->getColumnName($class->fieldNames[$joinColumn['referencedColumnName']], $class, $platform);
             $sql .= $joinTableAlias . '.' . $joinColumn['name'] . ' = ' . $sourceTableAlias . '.' . $sourceColumnName;
         }
     }
     return '(' . $sql . ')';
 }
開發者ID:BusinessCookies,項目名稱:CoffeeMachineProject,代碼行數:53,代碼來源:SizeFunction.php

示例2: getSql

 /**
  * {@inheritdoc}
  */
 public function getSql(SqlWalker $sqlWalker)
 {
     $platform = $sqlWalker->getEntityManager()->getConnection()->getDatabasePlatform();
     $quoteStrategy = $sqlWalker->getEntityManager()->getConfiguration()->getQuoteStrategy();
     $dqlAlias = $this->pathExpression->identificationVariable;
     $assocField = $this->pathExpression->field;
     $qComp = $sqlWalker->getQueryComponent($dqlAlias);
     $class = $qComp['metadata'];
     $assoc = $class->associationMappings[$assocField];
     $targetEntity = $sqlWalker->getEntityManager()->getClassMetadata($assoc['targetEntity']);
     $joinColumn = reset($assoc['joinColumns']);
     if ($this->fieldMapping !== null) {
         if (!isset($targetEntity->fieldMappings[$this->fieldMapping])) {
             throw new QueryException(sprintf('Undefined reference field mapping "%s"', $this->fieldMapping));
         }
         $field = $targetEntity->fieldMappings[$this->fieldMapping];
         $joinColumn = null;
         foreach ($assoc['joinColumns'] as $mapping) {
             if ($mapping['referencedColumnName'] === $field['columnName']) {
                 $joinColumn = $mapping;
                 break;
             }
         }
         if ($joinColumn === null) {
             throw new QueryException(sprintf('Unable to resolve the reference field mapping "%s"', $this->fieldMapping));
         }
     }
     // The table with the relation may be a subclass, so get the table name from the association definition
     $tableName = $sqlWalker->getEntityManager()->getClassMetadata($assoc['sourceEntity'])->getTableName();
     $tableAlias = $sqlWalker->getSQLTableAlias($tableName, $dqlAlias);
     $columnName = $quoteStrategy->getJoinColumnName($joinColumn, $targetEntity, $platform);
     return $tableAlias . '.' . $columnName;
 }
開發者ID:BusinessCookies,項目名稱:CoffeeMachineProject,代碼行數:36,代碼來源:IdentityFunction.php

示例3: getSql

 /**
  * @override
  */
 public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
 {
     $dqlAlias = $this->pathExpression->identificationVariable;
     $assocField = $this->pathExpression->field;
     $qComp = $sqlWalker->getQueryComponent($dqlAlias);
     $class = $qComp['metadata'];
     $assoc = $class->associationMappings[$assocField];
     $tableAlias = $sqlWalker->getSQLTableAlias($class->getTableName(), $dqlAlias);
     return $tableAlias . '.' . reset($assoc['targetToSourceKeyColumns']);
 }
開發者ID:dracony,項目名稱:forked-php-orm-benchmark,代碼行數:13,代碼來源:IdentityFunction.php

示例4: getSql

 /**
  * {@inheritdoc}
  */
 public function getSql(SqlWalker $sqlWalker)
 {
     $dqlAlias = $this->pathExpression->identificationVariable;
     $qComp = $sqlWalker->getQueryComponent($dqlAlias);
     $class = $qComp['metadata'];
     $tableAlias = $sqlWalker->getSQLTableAlias($class->getTableName(), $dqlAlias);
     if (is_array($class->discriminatorColumn) && isset($class->discriminatorColumn['name'])) {
         return $tableAlias . '.' . $class->discriminatorColumn['name'];
     } else {
         return '';
     }
 }
開發者ID:soundintheory,項目名稱:fuel-cmf,代碼行數:15,代碼來源:TypeFunction.php

示例5: testGetSQLTableAliasIsSameForMultipleCalls

 /**
  * @dataProvider getColumnNamesAndSqlAliases
  */
 public function testGetSQLTableAliasIsSameForMultipleCalls($tableName)
 {
     $this->assertSame($this->sqlWalker->getSQLTableAlias($tableName), $this->sqlWalker->getSQLTableAlias($tableName));
 }
開發者ID:selimcr,項目名稱:servigases,代碼行數:7,代碼來源:SqlWalkerTest.php


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