From 49621286a2f4ddd9823c6baae5f8b7cf39dd08ec Mon Sep 17 00:00:00 2001 From: romanb Date: Fri, 26 Mar 2010 22:07:31 +0000 Subject: [PATCH] [2.0][DDC-479] Fixed. --- lib/Doctrine/ORM/Query/SqlWalker.php | 20 +++++++++---------- .../ORM/Query/SelectSqlGenerationTest.php | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 8dd1c856b..17460360b 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -1349,33 +1349,33 @@ class SqlWalker implements TreeWalker // join conditions $joinColumns = $assoc->isOwningSide - ? $joinTable['joinColumns'] - : $joinTable['inverseJoinColumns']; + ? $joinTable['inverseJoinColumns'] + : $joinTable['joinColumns']; - $referencedColumnClass = $assoc->isOwningSide ? $class : $targetClass; + //$referencedColumnClass = $assoc->isOwningSide ? $targetClass : $class; $first = true; foreach ($joinColumns as $joinColumn) { if ($first) $first = false; else $sql .= ' AND '; $sql .= $joinTableAlias . '.' . $joinColumn['name'] . ' = ' - . $sourceTableAlias . '.' . $referencedColumnClass->getQuotedColumnName( - $referencedColumnClass->fieldNames[$joinColumn['referencedColumnName']], + . $targetTableAlias . '.' . $targetClass->getQuotedColumnName( + $targetClass->fieldNames[$joinColumn['referencedColumnName']], $this->_platform); } $sql .= ' WHERE '; $joinColumns = $assoc->isOwningSide - ? $joinTable['inverseJoinColumns'] - : $joinTable['joinColumns']; + ? $joinTable['joinColumns'] + : $joinTable['inverseJoinColumns']; $first = true; foreach ($joinColumns as $joinColumn) { if ($first) $first = false; else $sql .= ' AND '; - + $sql .= $joinTableAlias . '.' . $joinColumn['name'] . ' = ' - . $targetTableAlias . '.' . $referencedColumnClass->getQuotedColumnName( - $referencedColumnClass->fieldNames[$joinColumn['referencedColumnName']], + . $sourceTableAlias . '.' . $class->getQuotedColumnName( + $class->fieldNames[$joinColumn['referencedColumnName']], $this->_platform); } diff --git a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php index 303bd29de..163bc594e 100644 --- a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php @@ -348,7 +348,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase $q2->setParameter('param', $group); $this->assertEquals( - 'SELECT c0_.id AS id0 FROM cms_users c0_ WHERE EXISTS (SELECT 1 FROM cms_users_groups c1_ INNER JOIN cms_groups c2_ ON c1_.user_id = c0_.id WHERE c1_.group_id = c2_.id AND c2_.id = ?)', + 'SELECT c0_.id AS id0 FROM cms_users c0_ WHERE EXISTS (SELECT 1 FROM cms_users_groups c1_ INNER JOIN cms_groups c2_ ON c1_.group_id = c2_.id WHERE c1_.user_id = c0_.id AND c2_.id = ?)', $q2->getSql() ); @@ -359,7 +359,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase $this->_em->getClassMetadata(get_class($person))->setIdentifierValues($person, 101); $q3->setParameter('param', $person); $this->assertEquals( - 'SELECT c0_.id AS id0, c0_.name AS name1, c1_.title AS title2, c1_.car_id AS car_id3, c2_.salary AS salary4, c2_.department AS department5, c0_.discr AS discr6, c0_.spouse_id AS spouse_id7 FROM company_persons c0_ LEFT JOIN company_managers c1_ ON c0_.id = c1_.id LEFT JOIN company_employees c2_ ON c0_.id = c2_.id WHERE EXISTS (SELECT 1 FROM company_persons_friends c3_ INNER JOIN company_persons c4_ ON c3_.person_id = c0_.id WHERE c3_.friend_id = c4_.id AND c4_.id = ?)', + 'SELECT c0_.id AS id0, c0_.name AS name1, c1_.title AS title2, c1_.car_id AS car_id3, c2_.salary AS salary4, c2_.department AS department5, c0_.discr AS discr6, c0_.spouse_id AS spouse_id7 FROM company_persons c0_ LEFT JOIN company_managers c1_ ON c0_.id = c1_.id LEFT JOIN company_employees c2_ ON c0_.id = c2_.id WHERE EXISTS (SELECT 1 FROM company_persons_friends c3_ INNER JOIN company_persons c4_ ON c3_.friend_id = c4_.id WHERE c3_.person_id = c0_.id AND c4_.id = ?)', $q3->getSql() ); }