[2.0] DDC-163 - Missing DQL Alias prefix for many-to-many table in SqlWalker lead to duplicate prefix generation in SQL statement when a many-to-many join table is used more than once.
This commit is contained in:
parent
ac4c33c371
commit
005d3b432b
@ -704,7 +704,7 @@ class SqlWalker implements TreeWalker
|
|||||||
} else if ($assoc->isManyToMany()) {
|
} else if ($assoc->isManyToMany()) {
|
||||||
// Join relation table
|
// Join relation table
|
||||||
$joinTable = $assoc->getJoinTable();
|
$joinTable = $assoc->getJoinTable();
|
||||||
$joinTableAlias = $this->getSqlTableAlias($joinTable['name']);
|
$joinTableAlias = $this->getSqlTableAlias($joinTable['name'], $joinedDqlAlias);
|
||||||
$sql .= $assoc->getQuotedJoinTableName($this->_platform) . ' ' . $joinTableAlias . ' ON ';
|
$sql .= $assoc->getQuotedJoinTableName($this->_platform) . ' ' . $joinTableAlias . ' ON ';
|
||||||
|
|
||||||
if ($relation->isOwningSide) {
|
if ($relation->isOwningSide) {
|
||||||
|
65
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC163Test.php
Normal file
65
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC163Test.php
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||||
|
|
||||||
|
use Doctrine\Tests\Models\Company\CompanyPerson;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../../../TestInit.php';
|
||||||
|
|
||||||
|
class DDC163Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||||
|
{
|
||||||
|
protected function setUp()
|
||||||
|
{
|
||||||
|
$this->useModelSet('company');
|
||||||
|
parent::setUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group DDC-163
|
||||||
|
*/
|
||||||
|
public function testQueryWithOrConditionUsingTwoRelationOnSameEntity()
|
||||||
|
{
|
||||||
|
$p1 = new CompanyPerson;
|
||||||
|
$p1->setName('p1');
|
||||||
|
|
||||||
|
$p2 = new CompanyPerson;
|
||||||
|
$p2->setName('p2');
|
||||||
|
|
||||||
|
$p3 = new CompanyPerson;
|
||||||
|
$p3->setName('p3');
|
||||||
|
|
||||||
|
$p4 = new CompanyPerson;
|
||||||
|
$p4->setName('p4');
|
||||||
|
|
||||||
|
$p1->setSpouse($p3);
|
||||||
|
$p1->addFriend($p2);
|
||||||
|
$p2->addFriend($p3);
|
||||||
|
|
||||||
|
$p3->addFriend($p4);
|
||||||
|
|
||||||
|
$this->_em->persist($p1);
|
||||||
|
$this->_em->persist($p2);
|
||||||
|
$this->_em->persist($p3);
|
||||||
|
$this->_em->persist($p4);
|
||||||
|
|
||||||
|
$this->_em->flush();
|
||||||
|
$this->_em->clear();
|
||||||
|
|
||||||
|
$dql = 'SELECT person.name, spouse.name, friend.name
|
||||||
|
FROM Doctrine\Tests\Models\Company\CompanyPerson person
|
||||||
|
LEFT JOIN person.spouse spouse
|
||||||
|
LEFT JOIN person.friends friend
|
||||||
|
LEFT JOIN spouse.friends spouse_friend
|
||||||
|
LEFT JOIN friend.friends friend_friend
|
||||||
|
WHERE person.name=:name AND (spouse_friend.name=:name2 OR friend_friend.name=:name2)';
|
||||||
|
|
||||||
|
$q = $this->_em->createQuery($dql);
|
||||||
|
$q->setParameter('name', "p1");
|
||||||
|
$q->setParameter('name2', "p4");
|
||||||
|
$result = $q->getScalarResult();
|
||||||
|
|
||||||
|
$this->assertEquals('p3', $result[0]['spouse_name']);
|
||||||
|
$this->assertEquals('p1', $result[0]['person_name']);
|
||||||
|
$this->assertEquals('p2', $result[0]['friend_name']);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user