Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

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

Merged
merged 1 commit into from over 2 years ago

3 participants

Alexander Christophe Coevoet Benjamin Eberlei
Alexander
Collaborator

No description provided.

Christophe Coevoet

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

Christophe Coevoet

sorry, I read it too fast.

Benjamin Eberlei beberlei merged commit 91e700a into from December 18, 2011
Benjamin Eberlei beberlei closed this December 18, 2011
elHornair elHornair referenced this pull request from a commit February 22, 2013
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

Showing 1 unique commit by 1 author.

Dec 18, 2011
Alexander [DDC-1505] joinColumn "nullable" should be handled true by default de769c6
This page is out of date. Refresh to see the latest.
2  lib/Doctrine/ORM/Persisters/BasicEntityPersister.php
@@ -1563,7 +1563,7 @@ protected function getJoinSQLForJoinColumns($joinColumns)
1563 1563
     {
1564 1564
         // if one of the join columns is nullable, return left join
1565 1565
         foreach ($joinColumns as $joinColumn) {
1566  
-             if (isset($joinColumn['nullable']) && $joinColumn['nullable']) {
  1566
+             if (!isset($joinColumn['nullable']) || $joinColumn['nullable']) {
1567 1567
                  return 'LEFT JOIN';
1568 1568
              }
1569 1569
         }
23  tests/Doctrine/Tests/ORM/Functional/OneToOneEagerLoadingTest.php
@@ -143,15 +143,28 @@ public function testEagerLoadWithNullableColumnsGeneratesLeftJoinOnBothSides()
143 143
     public function testEagerLoadWithNonNullableColumnsGeneratesInnerJoinOnOwningSide()
144 144
     {
145 145
         $waggon = new Waggon();
146  
-        $this->_em->persist($waggon);
  146
+
  147
+        // It should have a train
  148
+        $train = new Train(new TrainOwner("Alexander"));
  149
+        $train->addWaggon($waggon);
  150
+
  151
+        $this->_em->persist($train);
147 152
         $this->_em->flush();
148 153
         $this->_em->clear();
149 154
 
150 155
         $waggon = $this->_em->find(get_class($waggon), $waggon->id);
  156
+
  157
+        // The last query is the eager loading of the owner of the train
151 158
         $this->assertEquals(
152  
-            "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 = ?",
  159
+            "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 (?)",
153 160
             $this->_sqlLoggerStack->queries[$this->_sqlLoggerStack->currentQuery]['sql']
154 161
         );
  162
+
  163
+        // The one before is the fetching of the waggon and train
  164
+        $this->assertEquals(
  165
+            "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 = ?",
  166
+            $this->_sqlLoggerStack->queries[$this->_sqlLoggerStack->currentQuery - 1]['sql']
  167
+        );
155 168
     }
156 169
 
157 170
     public function testEagerLoadWithNonNullableColumnsGeneratesLeftJoinOnNonOwningSide()
@@ -189,6 +202,7 @@ class Train
189 202
     /**
190 203
      * Owning side
191 204
      * @OneToOne(targetEntity="TrainOwner", inversedBy="train", fetch="EAGER", cascade={"persist"})
  205
+     * @JoinColumn(nullable=false)
192 206
      */
193 207
     public $owner;
194 208
     /**
@@ -280,7 +294,10 @@ class Waggon
280 294
 {
281 295
     /** @id @generatedValue @column(type="integer") */
282 296
     public $id;
283  
-    /** @ManyToOne(targetEntity="Train", inversedBy="waggons", fetch="EAGER") */
  297
+    /**
  298
+     * @ManyToOne(targetEntity="Train", inversedBy="waggons", fetch="EAGER")
  299
+     * @JoinColumn(nullable=false)
  300
+     */
284 301
     public $train;
285 302
 
286 303
     public function setTrain($train)
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.