diff --git a/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php b/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php index d9f7e30ca..1ec6e5e7c 100644 --- a/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php @@ -235,7 +235,7 @@ class ManyToManyPersister extends AbstractCollectionPersister foreach ($joinColumns as $joinColumn) { $columnName = $this->quoteStrategy->getJoinColumnName($joinColumn, $class, $this->platform); $referencedName = $joinColumn['referencedColumnName']; - $conditions[] = $columnName . ' = ?'; + $conditions[] = 't.' . $columnName . ' = ?'; $params[] = ($class->containsForeignIdentifier) ? $id[$class->getFieldForColumn($referencedName)] : $id[$class->fieldNames[$referencedName]]; @@ -361,12 +361,13 @@ class ManyToManyPersister extends AbstractCollectionPersister $params = array(); foreach ($mapping['joinTableColumns'] as $joinTableColumn) { - $whereClauses[] = $joinTableColumn . ' = ?'; + $whereClauses[] = ($addFilters ? 't.' : '') . $joinTableColumn . ' = ?'; if (isset($mapping['relationToTargetKeyColumns'][$joinTableColumn])) { $params[] = ($targetClass->containsForeignIdentifier) ? $targetId[$targetClass->getFieldForColumn($mapping['relationToTargetKeyColumns'][$joinTableColumn])] : $targetId[$targetClass->fieldNames[$mapping['relationToTargetKeyColumns'][$joinTableColumn]]]; + continue; } @@ -377,9 +378,12 @@ class ManyToManyPersister extends AbstractCollectionPersister } if ($addFilters) { + $quotedJoinTable .= ' t'; + list($joinTargetEntitySQL, $filterSql) = $this->getFilterSql($filterMapping); + if ($filterSql) { - $quotedJoinTable .= ' t ' . $joinTargetEntitySQL; + $quotedJoinTable .= ' ' . $joinTargetEntitySQL; $whereClauses[] = $filterSql; } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1595Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1595Test.php index a45c9f1f2..4ccb4c5f4 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1595Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1595Test.php @@ -53,7 +53,7 @@ class DDC1595Test extends \Doctrine\Tests\OrmFunctionalTestCase $entities = $entity1->getEntities()->count(); $this->assertEquals( - "SELECT COUNT(*) FROM entity1_entity2 t WHERE parent = ?", + "SELECT COUNT(*) FROM entity1_entity2 t WHERE t.parent = ?", $sqlLogger->queries[count($sqlLogger->queries)]['sql'] ); }