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


PHP SqlWalker::getQueryComponent方法代码示例

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


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

示例1: 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

示例2: getSql

 /**
  * @override
  */
 public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
 {
     $dqlAlias = $this->collectionPathExpression->identificationVariable;
     $parts = $this->collectionPathExpression->parts;
     $assocField = array_pop($parts);
     $qComp = $sqlWalker->getQueryComponent(implode('.', array_merge((array) $dqlAlias, $parts)));
     $assoc = $qComp['metadata']->associationMappings[$assocField];
     $sql = '';
     if ($assoc->isOneToMany()) {
         $targetClass = $sqlWalker->getEntityManager()->getClassMetadata($assoc->targetEntityName);
         $targetAssoc = $targetClass->associationMappings[$assoc->mappedByFieldName];
         $targetTableAlias = $sqlWalker->getSqlTableAlias($targetClass->primaryTable['name']);
         $sourceTableAlias = $sqlWalker->getSqlTableAlias($qComp['metadata']->primaryTable['name'], $dqlAlias);
         $whereSql = '';
         foreach ($targetAssoc->targetToSourceKeyColumns as $targetKeyColumn => $sourceKeyColumn) {
             $whereSql .= ($whereSql == '' ? ' WHERE ' : ' AND ') . $targetTableAlias . '.' . $sourceKeyColumn . ' = ' . $sourceTableAlias . '.' . $targetKeyColumn;
         }
         $sql = '(SELECT COUNT(' . "{$targetTableAlias}." . implode(", {$targetTableAlias}.", $targetAssoc->targetToSourceKeyColumns) . ') FROM ' . $targetClass->primaryTable['name'] . ' ' . $targetTableAlias . $whereSql . ')';
     } else {
         if ($assoc->isManyToMany()) {
             // TODO
             $targetTableAlias = $sqlWalker->getSqlTableAlias($assoc->joinTable['name']);
             $sourceTableAlias = $sqlWalker->getSqlTableAlias($qComp['metadata']->primaryTable['name'], $dqlAlias);
             $whereSql = '';
             foreach ($assoc->relationToSourceKeyColumns as $targetKeyColumn => $sourceKeyColumn) {
                 $whereSql .= ($whereSql == '' ? ' WHERE ' : ' AND ') . $targetTableAlias . '.' . $targetKeyColumn . ' = ' . $sourceTableAlias . '.' . $sourceKeyColumn;
             }
             $sql = '(SELECT COUNT(' . "{$targetTableAlias}." . implode(", {$targetTableAlias}.", $assoc->joinTableColumns) . ') FROM ' . $assoc->joinTable['name'] . ' ' . $targetTableAlias . $whereSql . ')';
         }
     }
     return $sql;
 }
开发者ID:nvdnkpr,项目名称:symfony-demo,代码行数:35,代码来源:SizeFunction.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: 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

示例6: findFTSField

 protected function findFTSField(SqlWalker $sqlWalker)
 {
     $reader = new AnnotationReader();
     $dqlAlias = $this->ftsField->identificationVariable;
     $class = $sqlWalker->getQueryComponent($dqlAlias);
     /** @var ClassMetadata $classMetaData */
     $classMetaData = $class['metadata'];
     $classRefl = $classMetaData->getReflectionClass();
     foreach ($classRefl->getProperties() as $prop) {
         /** @var TsVector $annot */
         $annot = $reader->getPropertyAnnotation($prop, TsVector::class);
         if (is_null($annot)) {
             continue;
         }
         if (in_array($this->ftsField->field, $annot->fields)) {
             $this->ftsField->field = $prop->name;
             break;
         }
     }
 }
开发者ID:jbinfo,项目名称:DoctrineFullTextPostrgres,代码行数:20,代码来源:TSFunction.php


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