Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 public function walkPathExpression($pathExpr)
 {
     $sql = '';
     switch ($pathExpr->type) {
         case AST\PathExpression::TYPE_STATE_FIELD:
             $fieldName = $pathExpr->field;
             $dqlAlias = $pathExpr->identificationVariable;
             $class = $this->queryComponents[$dqlAlias]['metadata'];
             if ($this->useSqlTableAliases) {
                 $sql .= $this->walkIdentificationVariable($dqlAlias, $fieldName) . '.';
             }
             $sql .= $this->quoteStrategy->getColumnName($fieldName, $class, $this->platform);
             break;
         case AST\PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION:
             // 1- the owning side:
             //    Just use the foreign key, i.e. u.group_id
             $fieldName = $pathExpr->field;
             $dqlAlias = $pathExpr->identificationVariable;
             $class = $this->queryComponents[$dqlAlias]['metadata'];
             if (isset($class->associationMappings[$fieldName]['inherited'])) {
                 $class = $this->em->getClassMetadata($class->associationMappings[$fieldName]['inherited']);
             }
             $assoc = $class->associationMappings[$fieldName];
             if (!$assoc['isOwningSide']) {
                 throw QueryException::associationPathInverseSideNotSupported();
             }
             // COMPOSITE KEYS NOT (YET?) SUPPORTED
             if (count($assoc['sourceToTargetKeyColumns']) > 1) {
                 throw QueryException::associationPathCompositeKeyNotSupported();
             }
             if ($this->useSqlTableAliases) {
                 $sql .= $this->getSQLTableAlias($class->getTableName(), $dqlAlias) . '.';
             }
             $sql .= reset($assoc['targetToSourceKeyColumns']);
             break;
         default:
             throw QueryException::invalidPathExpression($pathExpr);
     }
     return $sql;
 }
Beispiel #2
0
 /**
  * Walks down a PathExpression AST node, thereby generating the appropriate SQL.
  *
  * @param mixed
  * @return string The SQL.
  */
 public function walkPathExpression($pathExpr)
 {
     $sql = '';
     switch ($pathExpr->type) {
         case AST\PathExpression::TYPE_STATE_FIELD:
             $parts = $pathExpr->parts;
             $fieldName = array_pop($parts);
             $dqlAlias = $pathExpr->identificationVariable . (!empty($parts) ? '.' . implode('.', $parts) : '');
             $class = $this->_queryComponents[$dqlAlias]['metadata'];
             if ($this->_useSqlTableAliases) {
                 $sql .= $this->walkIdentificationVariable($dqlAlias, $fieldName) . '.';
             }
             $sql .= $class->getQuotedColumnName($fieldName, $this->_platform);
             break;
         case AST\PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION:
             // 1- the owning side:
             //    Just use the foreign key, i.e. u.group_id
             $parts = $pathExpr->parts;
             $fieldName = array_pop($parts);
             $dqlAlias = $pathExpr->identificationVariable;
             $class = $this->_queryComponents[$dqlAlias]['metadata'];
             $assoc = $class->associationMappings[$fieldName];
             if ($assoc->isOwningSide) {
                 // COMPOSITE KEYS NOT (YET?) SUPPORTED
                 if (count($assoc->sourceToTargetKeyColumns) > 1) {
                     throw QueryException::associationPathCompositeKeyNotSupported();
                 }
                 $sql .= $this->walkIdentificationVariable($dqlAlias) . '.' . reset($assoc->targetToSourceKeyColumns);
             } else {
                 // 2- Inverse side: NOT (YET?) SUPPORTED
                 throw QueryException::associationPathInverseSideNotSupported();
             }
             break;
         default:
             throw QueryException::invalidPathExpression($pathExpr);
     }
     return $sql;
 }