Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed issue with fetched association not being considered during chan…

…geSet calculation. Fixes DDC-1545.
  • Loading branch information...
commit a8478d5766e2cc4185612af680b7f6bcd83af61e 1 parent f6d9344
Guilherme Blanco authored December 19, 2011
6  lib/Doctrine/ORM/Query/SqlWalker.php
@@ -978,17 +978,13 @@ public function walkCaseExpression($expression)
978 978
      */
979 979
     public function walkCoalesceExpression($coalesceExpression)
980 980
     {
981  
-        $sql = 'COALESCE(';
982  
-
983 981
         $scalarExpressions = array();
984 982
 
985 983
         foreach ($coalesceExpression->scalarExpressions as $scalarExpression) {
986 984
             $scalarExpressions[] = $this->walkSimpleArithmeticExpression($scalarExpression);
987 985
         }
988 986
 
989  
-        $sql .= implode(', ', $scalarExpressions) . ')';
990  
-
991  
-        return $sql;
  987
+        return 'COALESCE(' . implode(', ', $scalarExpressions) . ')';
992 988
     }
993 989
 
994 990
     /**
27  lib/Doctrine/ORM/UnitOfWork.php
@@ -705,7 +705,6 @@ private function computeAssociationChanges($assoc, $value)
705 705
 
706 706
         foreach ($unwrappedValue as $key => $entry) {
707 707
             $state = $this->getEntityState($entry, self::STATE_NEW);
708  
-            $oid   = spl_object_hash($entry);
709 708
 
710 709
             switch ($state) {
711 710
                 case self::STATE_NEW:
@@ -2293,13 +2292,14 @@ public function createEntity($className, array $data, &$hints = array())
2293 2292
             $id = array($class->identifier[0] => $idHash);
2294 2293
         }
2295 2294
 
  2295
+        $overrideLocalValues = true;
  2296
+
2296 2297
         if (isset($this->identityMap[$class->rootEntityName][$idHash])) {
2297 2298
             $entity = $this->identityMap[$class->rootEntityName][$idHash];
2298 2299
             $oid = spl_object_hash($entity);
2299 2300
 
2300 2301
             if ($entity instanceof Proxy && ! $entity->__isInitialized__) {
2301 2302
                 $entity->__isInitialized__ = true;
2302  
-                $overrideLocalValues = true;
2303 2303
 
2304 2304
                 if ($entity instanceof NotifyPropertyChanged) {
2305 2305
                     $entity->addPropertyChangedListener($this);
@@ -2308,7 +2308,7 @@ public function createEntity($className, array $data, &$hints = array())
2308 2308
                 $overrideLocalValues = isset($hints[Query::HINT_REFRESH]);
2309 2309
 
2310 2310
                 // If only a specific entity is set to refresh, check that it's the one
2311  
-                if(isset($hints[Query::HINT_REFRESH_ENTITY])) {
  2311
+                if (isset($hints[Query::HINT_REFRESH_ENTITY])) {
2312 2312
                     $overrideLocalValues = $hints[Query::HINT_REFRESH_ENTITY] === $entity;
2313 2313
 
2314 2314
                     // inject ObjectManager into just loaded proxies.
@@ -2333,8 +2333,6 @@ public function createEntity($className, array $data, &$hints = array())
2333 2333
             if ($entity instanceof NotifyPropertyChanged) {
2334 2334
                 $entity->addPropertyChangedListener($this);
2335 2335
             }
2336  
-
2337  
-            $overrideLocalValues = true;
2338 2336
         }
2339 2337
 
2340 2338
         if ( ! $overrideLocalValues) {
@@ -2362,6 +2360,10 @@ public function createEntity($className, array $data, &$hints = array())
2362 2360
         foreach ($class->associationMappings as $field => $assoc) {
2363 2361
             // Check if the association is not among the fetch-joined associations already.
2364 2362
             if (isset($hints['fetchAlias']) && isset($hints['fetched'][$hints['fetchAlias']][$field])) {
  2363
+                // DDC-1545: Fetched associations must have original entity data set.
  2364
+                // Define NULL value right now, since next iteration may fill it with actual value.
  2365
+                $this->originalEntityData[$oid][$field] = null;
  2366
+
2365 2367
                 continue;
2366 2368
             }
2367 2369
 
@@ -2382,12 +2384,15 @@ public function createEntity($className, array $data, &$hints = array())
2382 2384
                     foreach ($assoc['targetToSourceKeyColumns'] as $targetColumn => $srcColumn) {
2383 2385
                         $joinColumnValue = isset($data[$srcColumn]) ? $data[$srcColumn] : null;
2384 2386
 
2385  
-                        if ($joinColumnValue !== null) {
2386  
-                            if ($targetClass->containsForeignIdentifier) {
2387  
-                                $associatedId[$targetClass->getFieldForColumn($targetColumn)] = $joinColumnValue;
2388  
-                            } else {
2389  
-                                $associatedId[$targetClass->fieldNames[$targetColumn]] = $joinColumnValue;
2390  
-                            }
  2387
+                        // Skip is join column value is null
  2388
+                        if ($joinColumnValue === null) {
  2389
+                            continue;
  2390
+                        }
  2391
+
  2392
+                        if ($targetClass->containsForeignIdentifier) {
  2393
+                            $associatedId[$targetClass->getFieldForColumn($targetColumn)] = $joinColumnValue;
  2394
+                        } else {
  2395
+                            $associatedId[$targetClass->fieldNames[$targetColumn]] = $joinColumnValue;
2391 2396
                         }
2392 2397
                     }
2393 2398
 
2  tests/Doctrine/Tests/Models/CMS/CmsArticle.php
@@ -36,7 +36,7 @@ class CmsArticle
36 36
      * @Version @column(type="integer")
37 37
      */
38 38
     public $version;
39  
-    
  39
+
40 40
     public function setAuthor(CmsUser $author) {
41 41
         $this->user = $author;
42 42
     }

1 note on commit a8478d5

Alexander
Collaborator

Can you also add the testcase provided by @bschussek? Or can @bschussek send a PR for the testcase?

Please sign in to comment.
Something went wrong with that request. Please try again.