Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed issue with fetched association not being considered during chan…

…geSet calculation. Fixes DDC-1545.
  • Loading branch information...
commit a8478d5766e2cc4185612af680b7f6bcd83af61e 1 parent f6d9344
@guilhermeblanco guilhermeblanco authored
View
6 lib/Doctrine/ORM/Query/SqlWalker.php
@@ -978,17 +978,13 @@ public function walkCaseExpression($expression)
*/
public function walkCoalesceExpression($coalesceExpression)
{
- $sql = 'COALESCE(';
-
$scalarExpressions = array();
foreach ($coalesceExpression->scalarExpressions as $scalarExpression) {
$scalarExpressions[] = $this->walkSimpleArithmeticExpression($scalarExpression);
}
- $sql .= implode(', ', $scalarExpressions) . ')';
-
- return $sql;
+ return 'COALESCE(' . implode(', ', $scalarExpressions) . ')';
}
/**
View
27 lib/Doctrine/ORM/UnitOfWork.php
@@ -705,7 +705,6 @@ private function computeAssociationChanges($assoc, $value)
foreach ($unwrappedValue as $key => $entry) {
$state = $this->getEntityState($entry, self::STATE_NEW);
- $oid = spl_object_hash($entry);
switch ($state) {
case self::STATE_NEW:
@@ -2293,13 +2292,14 @@ public function createEntity($className, array $data, &$hints = array())
$id = array($class->identifier[0] => $idHash);
}
+ $overrideLocalValues = true;
+
if (isset($this->identityMap[$class->rootEntityName][$idHash])) {
$entity = $this->identityMap[$class->rootEntityName][$idHash];
$oid = spl_object_hash($entity);
if ($entity instanceof Proxy && ! $entity->__isInitialized__) {
$entity->__isInitialized__ = true;
- $overrideLocalValues = true;
if ($entity instanceof NotifyPropertyChanged) {
$entity->addPropertyChangedListener($this);
@@ -2308,7 +2308,7 @@ public function createEntity($className, array $data, &$hints = array())
$overrideLocalValues = isset($hints[Query::HINT_REFRESH]);
// If only a specific entity is set to refresh, check that it's the one
- if(isset($hints[Query::HINT_REFRESH_ENTITY])) {
+ if (isset($hints[Query::HINT_REFRESH_ENTITY])) {
$overrideLocalValues = $hints[Query::HINT_REFRESH_ENTITY] === $entity;
// inject ObjectManager into just loaded proxies.
@@ -2333,8 +2333,6 @@ public function createEntity($className, array $data, &$hints = array())
if ($entity instanceof NotifyPropertyChanged) {
$entity->addPropertyChangedListener($this);
}
-
- $overrideLocalValues = true;
}
if ( ! $overrideLocalValues) {
@@ -2362,6 +2360,10 @@ public function createEntity($className, array $data, &$hints = array())
foreach ($class->associationMappings as $field => $assoc) {
// Check if the association is not among the fetch-joined associations already.
if (isset($hints['fetchAlias']) && isset($hints['fetched'][$hints['fetchAlias']][$field])) {
+ // DDC-1545: Fetched associations must have original entity data set.
+ // Define NULL value right now, since next iteration may fill it with actual value.
+ $this->originalEntityData[$oid][$field] = null;
+
continue;
}
@@ -2382,12 +2384,15 @@ public function createEntity($className, array $data, &$hints = array())
foreach ($assoc['targetToSourceKeyColumns'] as $targetColumn => $srcColumn) {
$joinColumnValue = isset($data[$srcColumn]) ? $data[$srcColumn] : null;
- if ($joinColumnValue !== null) {
- if ($targetClass->containsForeignIdentifier) {
- $associatedId[$targetClass->getFieldForColumn($targetColumn)] = $joinColumnValue;
- } else {
- $associatedId[$targetClass->fieldNames[$targetColumn]] = $joinColumnValue;
- }
+ // Skip is join column value is null
@Tobion
Tobion added a note

2 typos

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ if ($joinColumnValue === null) {
+ continue;
+ }
+
+ if ($targetClass->containsForeignIdentifier) {
+ $associatedId[$targetClass->getFieldForColumn($targetColumn)] = $joinColumnValue;
+ } else {
+ $associatedId[$targetClass->fieldNames[$targetColumn]] = $joinColumnValue;
}
}
View
2  tests/Doctrine/Tests/Models/CMS/CmsArticle.php
@@ -36,7 +36,7 @@ class CmsArticle
* @Version @column(type="integer")
*/
public $version;
-
+
public function setAuthor(CmsUser $author) {
$this->user = $author;
}

1 comment on commit a8478d5

@asm89
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.