1
0
mirror of synced 2025-01-30 20:11:49 +03:00

Fixed issue with fetched association not being considered during changeSet calculation. Fixes DDC-1545.

This commit is contained in:
Guilherme Blanco 2011-12-19 01:39:48 -05:00
parent f6d9344d89
commit a8478d5766
3 changed files with 18 additions and 17 deletions

View File

@ -978,17 +978,13 @@ class SqlWalker implements TreeWalker
*/ */
public function walkCoalesceExpression($coalesceExpression) public function walkCoalesceExpression($coalesceExpression)
{ {
$sql = 'COALESCE(';
$scalarExpressions = array(); $scalarExpressions = array();
foreach ($coalesceExpression->scalarExpressions as $scalarExpression) { foreach ($coalesceExpression->scalarExpressions as $scalarExpression) {
$scalarExpressions[] = $this->walkSimpleArithmeticExpression($scalarExpression); $scalarExpressions[] = $this->walkSimpleArithmeticExpression($scalarExpression);
} }
$sql .= implode(', ', $scalarExpressions) . ')'; return 'COALESCE(' . implode(', ', $scalarExpressions) . ')';
return $sql;
} }
/** /**

View File

@ -705,7 +705,6 @@ class UnitOfWork implements PropertyChangedListener
foreach ($unwrappedValue as $key => $entry) { foreach ($unwrappedValue as $key => $entry) {
$state = $this->getEntityState($entry, self::STATE_NEW); $state = $this->getEntityState($entry, self::STATE_NEW);
$oid = spl_object_hash($entry);
switch ($state) { switch ($state) {
case self::STATE_NEW: case self::STATE_NEW:
@ -2293,13 +2292,14 @@ class UnitOfWork implements PropertyChangedListener
$id = array($class->identifier[0] => $idHash); $id = array($class->identifier[0] => $idHash);
} }
$overrideLocalValues = true;
if (isset($this->identityMap[$class->rootEntityName][$idHash])) { if (isset($this->identityMap[$class->rootEntityName][$idHash])) {
$entity = $this->identityMap[$class->rootEntityName][$idHash]; $entity = $this->identityMap[$class->rootEntityName][$idHash];
$oid = spl_object_hash($entity); $oid = spl_object_hash($entity);
if ($entity instanceof Proxy && ! $entity->__isInitialized__) { if ($entity instanceof Proxy && ! $entity->__isInitialized__) {
$entity->__isInitialized__ = true; $entity->__isInitialized__ = true;
$overrideLocalValues = true;
if ($entity instanceof NotifyPropertyChanged) { if ($entity instanceof NotifyPropertyChanged) {
$entity->addPropertyChangedListener($this); $entity->addPropertyChangedListener($this);
@ -2308,7 +2308,7 @@ class UnitOfWork implements PropertyChangedListener
$overrideLocalValues = isset($hints[Query::HINT_REFRESH]); $overrideLocalValues = isset($hints[Query::HINT_REFRESH]);
// If only a specific entity is set to refresh, check that it's the one // 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; $overrideLocalValues = $hints[Query::HINT_REFRESH_ENTITY] === $entity;
// inject ObjectManager into just loaded proxies. // inject ObjectManager into just loaded proxies.
@ -2333,8 +2333,6 @@ class UnitOfWork implements PropertyChangedListener
if ($entity instanceof NotifyPropertyChanged) { if ($entity instanceof NotifyPropertyChanged) {
$entity->addPropertyChangedListener($this); $entity->addPropertyChangedListener($this);
} }
$overrideLocalValues = true;
} }
if ( ! $overrideLocalValues) { if ( ! $overrideLocalValues) {
@ -2362,6 +2360,10 @@ class UnitOfWork implements PropertyChangedListener
foreach ($class->associationMappings as $field => $assoc) { foreach ($class->associationMappings as $field => $assoc) {
// Check if the association is not among the fetch-joined associations already. // Check if the association is not among the fetch-joined associations already.
if (isset($hints['fetchAlias']) && isset($hints['fetched'][$hints['fetchAlias']][$field])) { 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; continue;
} }
@ -2382,12 +2384,15 @@ class UnitOfWork implements PropertyChangedListener
foreach ($assoc['targetToSourceKeyColumns'] as $targetColumn => $srcColumn) { foreach ($assoc['targetToSourceKeyColumns'] as $targetColumn => $srcColumn) {
$joinColumnValue = isset($data[$srcColumn]) ? $data[$srcColumn] : null; $joinColumnValue = isset($data[$srcColumn]) ? $data[$srcColumn] : null;
if ($joinColumnValue !== null) { // Skip is join column value is null
if ($targetClass->containsForeignIdentifier) { if ($joinColumnValue === null) {
$associatedId[$targetClass->getFieldForColumn($targetColumn)] = $joinColumnValue; continue;
} else { }
$associatedId[$targetClass->fieldNames[$targetColumn]] = $joinColumnValue;
} if ($targetClass->containsForeignIdentifier) {
$associatedId[$targetClass->getFieldForColumn($targetColumn)] = $joinColumnValue;
} else {
$associatedId[$targetClass->fieldNames[$targetColumn]] = $joinColumnValue;
} }
} }

View File

@ -36,7 +36,7 @@ class CmsArticle
* @Version @column(type="integer") * @Version @column(type="integer")
*/ */
public $version; public $version;
public function setAuthor(CmsUser $author) { public function setAuthor(CmsUser $author) {
$this->user = $author; $this->user = $author;
} }