Skip to content

Commit

Permalink
Fixed invalid generation 'where expresion' sql when 'Type' in use SQL…
Browse files Browse the repository at this point in the history
…Conversion (doctrine#9989)
  • Loading branch information
Dzmitry Bannik committed Aug 12, 2022
1 parent 41bca04 commit 082124a
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions lib/Doctrine/ORM/Query/SqlWalker.php
Original file line number Diff line number Diff line change
Expand Up @@ -576,15 +576,20 @@ public function walkPathExpression(AST\PathExpression $pathExpr): string

switch ($pathExpr->type) {
case AST\PathExpression::TYPE_STATE_FIELD:
$fieldName = $pathExpr->field;
$dqlAlias = $pathExpr->identificationVariable;
$class = $this->getMetadataForDqlAlias($dqlAlias);
$fieldName = $pathExpr->field;
$dqlAlias = $pathExpr->identificationVariable;
$class = $this->getMetadataForDqlAlias($dqlAlias);
$fieldMapping = $class->getFieldMapping($fieldName);

if ($this->useSqlTableAliases) {
$sql .= $this->walkIdentificationVariable($dqlAlias, $fieldName) . '.';
}

$sql .= $this->quoteStrategy->getColumnName($fieldName, $class, $this->platform);

if (is_string($fieldMapping['type']) && Type::hasType($fieldMapping['type'])) {
$sql = Type::getType($fieldMapping['type'])->convertToPHPValueSQL($sql, $this->platform);
}
break;

case AST\PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION:
Expand Down Expand Up @@ -1224,21 +1229,11 @@ public function walkSelectExpression(AST\SelectExpression $selectExpression): st
$dqlAlias = $expr->identificationVariable;
$class = $this->getMetadataForDqlAlias($dqlAlias);

$resultAlias = $selectExpression->fieldIdentificationVariable ?: $fieldName;
$tableName = $class->isInheritanceTypeJoined()
? $this->em->getUnitOfWork()->getEntityPersister($class->name)->getOwningTable($fieldName)
: $class->getTableName();
$resultAlias = $selectExpression->fieldIdentificationVariable ?: $fieldName;
$fieldMapping = $class->fieldMappings[$fieldName];
$columnAlias = $this->getSQLColumnAlias($fieldMapping['columnName']);

$sqlTableAlias = $this->getSQLTableAlias($tableName, $dqlAlias);
$fieldMapping = $class->fieldMappings[$fieldName];
$columnName = $this->quoteStrategy->getColumnName($fieldName, $class, $this->platform);
$columnAlias = $this->getSQLColumnAlias($fieldMapping['columnName']);
$col = $sqlTableAlias . '.' . $columnName;

$type = Type::getType($fieldMapping['type']);
$col = $type->convertToPHPValueSQL($col, $this->conn->getDatabasePlatform());

$sql .= $col . ' AS ' . $columnAlias;
$sql .= $expr->dispatch($this) . ' AS ' . $columnAlias;

$this->scalarResultAliasMap[$resultAlias] = $columnAlias;

Expand Down Expand Up @@ -1481,9 +1476,6 @@ public function walkNewObject(AST\NewObjectExpression $newObjectExpression, ?str
$fieldType = $fieldMapping['type'];
$col = trim($e->dispatch($this));

$type = Type::getType($fieldType);
$col = $type->convertToPHPValueSQL($col, $this->platform);

$sqlSelectExpressions[] = $col . ' AS ' . $columnAlias;

if (! empty($fieldMapping['enumType'])) {
Expand Down

0 comments on commit 082124a

Please sign in to comment.