1
0
mirror of synced 2024-12-14 07:06:04 +03:00

Fix TODO: Inner join when all join columns are NOT nullable.

This commit is contained in:
Alexander 2011-10-31 21:36:55 +01:00
parent cfe7ab46f2
commit 3994b80aa4
2 changed files with 23 additions and 3 deletions

View File

@ -1002,10 +1002,10 @@ class BasicEntityPersister
}
}
$this->_selectJoinSql .= ' LEFT JOIN'; // TODO: Inner join when all join columns are NOT nullable.
$first = true;
if ($assoc['isOwningSide']) {
$this->_selectJoinSql .= $this->getJoinSQLForJoinColumns($assoc['joinColumns']);
$this->_selectJoinSql .= ' ' . $eagerEntity->getQuotedTableName($this->_platform) . ' ' . $this->_getSQLTableAlias($eagerEntity->name, $assocAlias) .' ON ';
foreach ($assoc['sourceToTargetKeyColumns'] AS $sourceCol => $targetCol) {
@ -1020,7 +1020,8 @@ class BasicEntityPersister
} else {
$eagerEntity = $this->_em->getClassMetadata($assoc['targetEntity']);
$owningAssoc = $eagerEntity->getAssociationMapping($assoc['mappedBy']);
$this->_selectJoinSql .= $this->getJoinSQLForJoinColumns($owningAssoc['joinColumns']);
$this->_selectJoinSql .= ' ' . $eagerEntity->getQuotedTableName($this->_platform) . ' '
. $this->_getSQLTableAlias($eagerEntity->name, $assocAlias) . ' ON ';
@ -1500,4 +1501,22 @@ class BasicEntityPersister
return (bool) $this->_conn->fetchColumn($sql, $params);
}
/**
* Generates the appropriate join SQL for the given join column.
*
* @param array $joinColumns The join columns definition of an association.
* @return string LEFT JOIN if one of the columns is nullable, INNER JOIN otherwise.
*/
protected function getJoinSQLForJoinColumns($joinColumns)
{
// if one of the join columns is nullable, return left join
foreach($joinColumns as $joinColumn) {
if(isset($joinColumn['nullable']) && $joinColumn['nullable']){
return ' LEFT JOIN ';
}
}
return ' INNER JOIN ';
}
}

View File

@ -130,6 +130,7 @@ class Train
/**
* Owning side
* @OneToOne(targetEntity="TrainDriver", inversedBy="train", fetch="EAGER", cascade={"persist"})
* @JoinColumn(nullable=true)
*/
public $driver;
/**
@ -195,4 +196,4 @@ class Waggon
{
$this->train = $train;
}
}
}