1
0
mirror of synced 2025-01-19 06:51:40 +03:00

Merge pull request #767 from doctrine/DDC-2627

Fixing missing table aliases when using Many2Many persister.
This commit is contained in:
Guilherme Blanco 2013-08-21 20:56:18 -07:00
commit c399c77dbe
2 changed files with 8 additions and 4 deletions

View File

@ -235,7 +235,7 @@ class ManyToManyPersister extends AbstractCollectionPersister
foreach ($joinColumns as $joinColumn) { foreach ($joinColumns as $joinColumn) {
$columnName = $this->quoteStrategy->getJoinColumnName($joinColumn, $class, $this->platform); $columnName = $this->quoteStrategy->getJoinColumnName($joinColumn, $class, $this->platform);
$referencedName = $joinColumn['referencedColumnName']; $referencedName = $joinColumn['referencedColumnName'];
$conditions[] = $columnName . ' = ?'; $conditions[] = 't.' . $columnName . ' = ?';
$params[] = ($class->containsForeignIdentifier) $params[] = ($class->containsForeignIdentifier)
? $id[$class->getFieldForColumn($referencedName)] ? $id[$class->getFieldForColumn($referencedName)]
: $id[$class->fieldNames[$referencedName]]; : $id[$class->fieldNames[$referencedName]];
@ -361,12 +361,13 @@ class ManyToManyPersister extends AbstractCollectionPersister
$params = array(); $params = array();
foreach ($mapping['joinTableColumns'] as $joinTableColumn) { foreach ($mapping['joinTableColumns'] as $joinTableColumn) {
$whereClauses[] = $joinTableColumn . ' = ?'; $whereClauses[] = ($addFilters ? 't.' : '') . $joinTableColumn . ' = ?';
if (isset($mapping['relationToTargetKeyColumns'][$joinTableColumn])) { if (isset($mapping['relationToTargetKeyColumns'][$joinTableColumn])) {
$params[] = ($targetClass->containsForeignIdentifier) $params[] = ($targetClass->containsForeignIdentifier)
? $targetId[$targetClass->getFieldForColumn($mapping['relationToTargetKeyColumns'][$joinTableColumn])] ? $targetId[$targetClass->getFieldForColumn($mapping['relationToTargetKeyColumns'][$joinTableColumn])]
: $targetId[$targetClass->fieldNames[$mapping['relationToTargetKeyColumns'][$joinTableColumn]]]; : $targetId[$targetClass->fieldNames[$mapping['relationToTargetKeyColumns'][$joinTableColumn]]];
continue; continue;
} }
@ -377,9 +378,12 @@ class ManyToManyPersister extends AbstractCollectionPersister
} }
if ($addFilters) { if ($addFilters) {
$quotedJoinTable .= ' t';
list($joinTargetEntitySQL, $filterSql) = $this->getFilterSql($filterMapping); list($joinTargetEntitySQL, $filterSql) = $this->getFilterSql($filterMapping);
if ($filterSql) { if ($filterSql) {
$quotedJoinTable .= ' t ' . $joinTargetEntitySQL; $quotedJoinTable .= ' ' . $joinTargetEntitySQL;
$whereClauses[] = $filterSql; $whereClauses[] = $filterSql;
} }
} }

View File

@ -53,7 +53,7 @@ class DDC1595Test extends \Doctrine\Tests\OrmFunctionalTestCase
$entities = $entity1->getEntities()->count(); $entities = $entity1->getEntities()->count();
$this->assertEquals( $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'] $sqlLogger->queries[count($sqlLogger->queries)]['sql']
); );
} }