Commit 005d3b43 authored by beberlei's avatar beberlei

[2.0] DDC-163 - Missing DQL Alias prefix for many-to-many table in SqlWalker...

[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.
parent ac4c33c3
......@@ -704,7 +704,7 @@ class SqlWalker implements TreeWalker
} else if ($assoc->isManyToMany()) {
// Join relation table
$joinTable = $assoc->getJoinTable();
$joinTableAlias = $this->getSqlTableAlias($joinTable['name']);
$joinTableAlias = $this->getSqlTableAlias($joinTable['name'], $joinedDqlAlias);
$sql .= $assoc->getQuotedJoinTableName($this->_platform) . ' ' . $joinTableAlias . ' ON ';
if ($relation->isOwningSide) {
......
<?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']);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment