Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Merged
merged 1 commit into from

3 participants

@asm89
Collaborator

No description provided.

@stof

a join column is nullable when the mapping is omitted (whereas standard columns are not nullable in such case). So this change is wrong

@stof

sorry, I read it too fast.

@beberlei beberlei merged commit 91e700a into from
@elHornair elHornair referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
2  lib/Doctrine/ORM/Persisters/BasicEntityPersister.php
@@ -1563,7 +1563,7 @@ 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']) {
+ if (!isset($joinColumn['nullable']) || $joinColumn['nullable']) {
return 'LEFT JOIN';
}
}
View
23 tests/Doctrine/Tests/ORM/Functional/OneToOneEagerLoadingTest.php
@@ -143,15 +143,28 @@ public function testEagerLoadWithNullableColumnsGeneratesLeftJoinOnBothSides()
public function testEagerLoadWithNonNullableColumnsGeneratesInnerJoinOnOwningSide()
{
$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->clear();
$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.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.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(
+ "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 - 1]['sql']
+ );
}
public function testEagerLoadWithNonNullableColumnsGeneratesLeftJoinOnNonOwningSide()
@@ -189,6 +202,7 @@ class Train
/**
* Owning side
* @OneToOne(targetEntity="TrainOwner", inversedBy="train", fetch="EAGER", cascade={"persist"})
+ * @JoinColumn(nullable=false)
*/
public $owner;
/**
@@ -280,7 +294,10 @@ class Waggon
{
/** @id @generatedValue @column(type="integer") */
public $id;
- /** @ManyToOne(targetEntity="Train", inversedBy="waggons", fetch="EAGER") */
+ /**
+ * @ManyToOne(targetEntity="Train", inversedBy="waggons", fetch="EAGER")
+ * @JoinColumn(nullable=false)
+ */
public $train;
public function setTrain($train)
Something went wrong with that request. Please try again.