test quote join variable
This commit is contained in:
parent
e0a236a9af
commit
b6b35d9482
@ -835,22 +835,17 @@ class SqlWalker implements TreeWalker
|
|||||||
case ($assoc['type'] & ClassMetadata::TO_ONE):
|
case ($assoc['type'] & ClassMetadata::TO_ONE):
|
||||||
$conditions = array();
|
$conditions = array();
|
||||||
|
|
||||||
foreach ($assoc['sourceToTargetKeyColumns'] as $sourceColumn => $targetColumn) {
|
foreach ($assoc['joinColumns'] as $joinColumn) {
|
||||||
if ($relation['isOwningSide']) {
|
$quotedSourceColumn = $this->quoteStrategy->getJoinColumnName($joinColumn, $targetClass, $this->platform);
|
||||||
$quotedTargetColumn = ($targetClass->containsForeignIdentifier && !isset($targetClass->fieldNames[$targetColumn]))
|
$quotedTargetColumn = $this->quoteStrategy->getReferencedJoinColumnName($joinColumn, $targetClass, $this->platform);
|
||||||
? $targetColumn // Join columns cannot be quoted.
|
|
||||||
: $targetClass->getQuotedColumnName($targetClass->fieldNames[$targetColumn], $this->platform);
|
|
||||||
|
|
||||||
$conditions[] = $sourceTableAlias . '.' . $sourceColumn . ' = ' . $targetTableAlias . '.' . $quotedTargetColumn;
|
if ($relation['isOwningSide']) {
|
||||||
|
$conditions[] = $sourceTableAlias . '.' . $quotedSourceColumn . ' = ' . $targetTableAlias . '.' . $quotedTargetColumn;
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$quotedTargetColumn = ($sourceClass->containsForeignIdentifier && !isset($sourceClass->fieldNames[$targetColumn]))
|
$conditions[] = $sourceTableAlias . '.' . $quotedTargetColumn . ' = ' . $targetTableAlias . '.' . $quotedSourceColumn;
|
||||||
? $targetColumn // Join columns cannot be quoted.
|
|
||||||
: $sourceClass->getQuotedColumnName($sourceClass->fieldNames[$targetColumn], $this->platform);
|
|
||||||
|
|
||||||
$conditions[] = $sourceTableAlias . '.' . $quotedTargetColumn . ' = ' . $targetTableAlias . '.' . $sourceColumn;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply remaining inheritance restrictions
|
// Apply remaining inheritance restrictions
|
||||||
@ -878,15 +873,14 @@ class SqlWalker implements TreeWalker
|
|||||||
|
|
||||||
$conditions = array();
|
$conditions = array();
|
||||||
$relationColumns = ($relation['isOwningSide'])
|
$relationColumns = ($relation['isOwningSide'])
|
||||||
? $assoc['relationToSourceKeyColumns']
|
? $assoc['joinTable']['joinColumns']
|
||||||
: $assoc['relationToTargetKeyColumns'];
|
: $assoc['joinTable']['inverseJoinColumns'];
|
||||||
|
|
||||||
foreach ($relationColumns as $relationColumn => $sourceColumn) {
|
foreach ($relationColumns as $joinColumn) {
|
||||||
$quotedTargetColumn = ($sourceClass->containsForeignIdentifier && !isset($sourceClass->fieldNames[$sourceColumn]))
|
$quotedSourceColumn = $this->quoteStrategy->getJoinColumnName($joinColumn, $targetClass, $this->platform);
|
||||||
? $sourceColumn // Join columns cannot be quoted.
|
$quotedTargetColumn = $this->quoteStrategy->getReferencedJoinColumnName($joinColumn, $targetClass, $this->platform);
|
||||||
: $sourceClass->getQuotedColumnName($sourceClass->fieldNames[$sourceColumn], $this->platform);
|
|
||||||
|
|
||||||
$conditions[] = $sourceTableAlias . '.' . $quotedTargetColumn . ' = ' . $joinTableAlias . '.' . $relationColumn;
|
$conditions[] = $sourceTableAlias . '.' . $quotedTargetColumn . ' = ' . $joinTableAlias . '.' . $quotedSourceColumn;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql .= $joinTableName . ' ' . $joinTableAlias . ' ON ' . implode(' AND ', $conditions);
|
$sql .= $joinTableName . ' ' . $joinTableAlias . ' ON ' . implode(' AND ', $conditions);
|
||||||
@ -896,15 +890,14 @@ class SqlWalker implements TreeWalker
|
|||||||
|
|
||||||
$conditions = array();
|
$conditions = array();
|
||||||
$relationColumns = ($relation['isOwningSide'])
|
$relationColumns = ($relation['isOwningSide'])
|
||||||
? $assoc['relationToTargetKeyColumns']
|
? $assoc['joinTable']['inverseJoinColumns']
|
||||||
: $assoc['relationToSourceKeyColumns'];
|
: $assoc['joinTable']['joinColumns'];
|
||||||
|
|
||||||
foreach ($relationColumns as $relationColumn => $targetColumn) {
|
foreach ($relationColumns as $joinColumn) {
|
||||||
$quotedTargetColumn = ($targetClass->containsForeignIdentifier && !isset($targetClass->fieldNames[$targetColumn]))
|
$quotedSourceColumn = $this->quoteStrategy->getJoinColumnName($joinColumn, $targetClass, $this->platform);
|
||||||
? $targetColumn // Join columns cannot be quoted.
|
$quotedTargetColumn = $this->quoteStrategy->getReferencedJoinColumnName($joinColumn, $targetClass, $this->platform);
|
||||||
: $targetClass->getQuotedColumnName($targetClass->fieldNames[$targetColumn], $this->platform);
|
|
||||||
|
|
||||||
$conditions[] = $targetTableAlias . '.' . $quotedTargetColumn . ' = ' . $joinTableAlias . '.' . $relationColumn;
|
$conditions[] = $targetTableAlias . '.' . $quotedTargetColumn . ' = ' . $joinTableAlias . '.' . $quotedSourceColumn;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply remaining inheritance restrictions
|
// Apply remaining inheritance restrictions
|
||||||
|
@ -1662,8 +1662,42 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
/**
|
||||||
|
* @group DDC-1845
|
||||||
|
*/
|
||||||
|
public function testQuotedWalkJoinVariableDeclaration()
|
||||||
|
{
|
||||||
|
$this->assertSqlGeneration(
|
||||||
|
'SELECT u, a FROM Doctrine\Tests\Models\Quote\User u JOIN u.address a',
|
||||||
|
'SELECT q0_."user-id" AS userid0, q0_."user-name" AS username1, q1_."address-id" AS addressid2, q1_."address-zip" AS addresszip3 FROM "quote-user" q0_ INNER JOIN "quote-address" q1_ ON q0_."address-id" = q1_."address-id"'
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertSqlGeneration(
|
||||||
|
'SELECT u, p FROM Doctrine\Tests\Models\Quote\User u JOIN u.phones p',
|
||||||
|
'SELECT q0_."user-id" AS userid0, q0_."user-name" AS username1, q1_."phone-number" AS phonenumber2 FROM "quote-user" q0_ INNER JOIN "quote-phone" q1_ ON q0_."user-id" = q1_."user-id"'
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertSqlGeneration(
|
||||||
|
'SELECT u, g FROM Doctrine\Tests\Models\Quote\User u JOIN u.groups g',
|
||||||
|
'SELECT q0_."user-id" AS userid0, q0_."user-name" AS username1, q1_."group-id" AS groupid2, q1_."group-name" AS groupname3 FROM "quote-user" q0_ INNER JOIN "quote-users-groups" q2_ ON q0_."user-id" = q2_."user-id" INNER JOIN "quote-group" q1_ ON q1_."group-id" = q2_."group-id"'
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertSqlGeneration(
|
||||||
|
'SELECT a, u FROM Doctrine\Tests\Models\Quote\Address a JOIN a.user u',
|
||||||
|
'SELECT q0_."address-id" AS addressid0, q0_."address-zip" AS addresszip1, q1_."user-id" AS userid2, q1_."user-name" AS username3 FROM "quote-address" q0_ INNER JOIN "quote-user" q1_ ON q0_."user-id" = q1_."user-id"'
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertSqlGeneration(
|
||||||
|
'SELECT g, u FROM Doctrine\Tests\Models\Quote\Group g JOIN g.users u',
|
||||||
|
'SELECT q0_."group-id" AS groupid0, q0_."group-name" AS groupname1, q1_."user-id" AS userid2, q1_."user-name" AS username3 FROM "quote-group" q0_ INNER JOIN "quote-users-groups" q2_ ON q0_."group-id" = q2_."group-id" INNER JOIN "quote-user" q1_ ON q1_."user-id" = q2_."user-id"'
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertSqlGeneration(
|
||||||
|
'SELECT g, p FROM Doctrine\Tests\Models\Quote\Group g JOIN g.parent p',
|
||||||
|
'SELECT q0_."group-id" AS groupid0, q0_."group-name" AS groupname1, q1_."group-id" AS groupid2, q1_."group-name" AS groupname3 FROM "quote-group" q0_ INNER JOIN "quote-group" q1_ ON q0_."parent-id" = q1_."group-id"'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class MyAbsFunction extends \Doctrine\ORM\Query\AST\Functions\FunctionNode
|
class MyAbsFunction extends \Doctrine\ORM\Query\AST\Functions\FunctionNode
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user