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

[DDC-1505] joinColumn "nullable" should be handled true by default

This commit is contained in:
Alexander 2011-12-18 21:33:38 +01:00
parent 29fabbd81f
commit de769c6c3c
2 changed files with 21 additions and 4 deletions

View File

@ -1563,7 +1563,7 @@ class BasicEntityPersister
{ {
// if one of the join columns is nullable, return left join // if one of the join columns is nullable, return left join
foreach ($joinColumns as $joinColumn) { foreach ($joinColumns as $joinColumn) {
if (isset($joinColumn['nullable']) && $joinColumn['nullable']) { if (!isset($joinColumn['nullable']) || $joinColumn['nullable']) {
return 'LEFT JOIN'; return 'LEFT JOIN';
} }
} }

View File

@ -143,14 +143,27 @@ class OneToOneEagerLoadingTest extends \Doctrine\Tests\OrmFunctionalTestCase
public function testEagerLoadWithNonNullableColumnsGeneratesInnerJoinOnOwningSide() public function testEagerLoadWithNonNullableColumnsGeneratesInnerJoinOnOwningSide()
{ {
$waggon = new Waggon(); $waggon = new Waggon();
$this->_em->persist($waggon);
// It should have a train
$train = new Train(new TrainOwner("Alexander"));
$train->addWaggon($waggon);
$this->_em->persist($train);
$this->_em->flush(); $this->_em->flush();
$this->_em->clear(); $this->_em->clear();
$waggon = $this->_em->find(get_class($waggon), $waggon->id); $waggon = $this->_em->find(get_class($waggon), $waggon->id);
// The last query is the eager loading of the owner of the train
$this->assertEquals(
"SELECT t0.id AS id1, t0.name AS name2, t3.id AS id4, t3.driver_id AS driver_id5, t3.owner_id AS owner_id6 FROM TrainOwner t0 LEFT JOIN Train t3 ON t3.owner_id = t0.id WHERE t0.id IN (?)",
$this->_sqlLoggerStack->queries[$this->_sqlLoggerStack->currentQuery]['sql']
);
// The one before is the fetching of the waggon and train
$this->assertEquals( $this->assertEquals(
"SELECT t0.id AS id1, t0.train_id AS train_id2, t3.id AS id4, t3.driver_id AS driver_id5, t3.owner_id AS owner_id6 FROM Waggon t0 INNER JOIN Train t3 ON t0.train_id = t3.id WHERE t0.id = ?", "SELECT t0.id AS id1, t0.train_id AS train_id2, t3.id AS id4, t3.driver_id AS driver_id5, t3.owner_id AS owner_id6 FROM Waggon t0 INNER JOIN Train t3 ON t0.train_id = t3.id WHERE t0.id = ?",
$this->_sqlLoggerStack->queries[$this->_sqlLoggerStack->currentQuery]['sql'] $this->_sqlLoggerStack->queries[$this->_sqlLoggerStack->currentQuery - 1]['sql']
); );
} }
@ -189,6 +202,7 @@ class Train
/** /**
* Owning side * Owning side
* @OneToOne(targetEntity="TrainOwner", inversedBy="train", fetch="EAGER", cascade={"persist"}) * @OneToOne(targetEntity="TrainOwner", inversedBy="train", fetch="EAGER", cascade={"persist"})
* @JoinColumn(nullable=false)
*/ */
public $owner; public $owner;
/** /**
@ -280,7 +294,10 @@ class Waggon
{ {
/** @id @generatedValue @column(type="integer") */ /** @id @generatedValue @column(type="integer") */
public $id; public $id;
/** @ManyToOne(targetEntity="Train", inversedBy="waggons", fetch="EAGER") */ /**
* @ManyToOne(targetEntity="Train", inversedBy="waggons", fetch="EAGER")
* @JoinColumn(nullable=false)
*/
public $train; public $train;
public function setTrain($train) public function setTrain($train)