1
0
mirror of synced 2024-12-14 07:06:04 +03:00
This commit is contained in:
zYne 2007-05-30 10:38:48 +00:00
parent 12a9f30a76
commit b234e717ed

View File

@ -680,30 +680,7 @@ class Doctrine_Hydrate implements Serializable
} }
return $array; return $array;
} }
/**
* isIdentifiable
* returns whether or not a given data row is identifiable (it contains
* all primary key fields specified in the second argument)
*
* @param array $row
* @param mixed $primaryKeys
* @return boolean
*/
public function isIdentifiable(array $row, $primaryKeys)
{
if (is_array($primaryKeys)) {
foreach ($primaryKeys as $id) {
if ($row[$id] == null) {
return false;
}
}
} else {
if ( ! isset($row[$primaryKeys])) {
return false;
}
}
return true;
}
/** /**
* getType * getType
* *
@ -829,6 +806,7 @@ class Doctrine_Hydrate implements Serializable
$alias = $cache[$key]['alias']; $alias = $cache[$key]['alias'];
$component = $cache[$key]['component']; $component = $cache[$key]['component'];
$componentName = $this->_aliasMap[$cache[$key]['alias']]['table']->getComponentName(); $componentName = $this->_aliasMap[$cache[$key]['alias']]['table']->getComponentName();
$table = $this->_aliasMap[$cache[$key]['alias']]['table'];
if ( ! isset($currData[$alias])) { if ( ! isset($currData[$alias])) {
@ -842,25 +820,18 @@ class Doctrine_Hydrate implements Serializable
if ($alias !== $lastAlias || $parse) { if ($alias !== $lastAlias || $parse) {
// component changed // component changed
if ( ! isset($prevData[$alias]) || (isset($currData[$alias]) && $currData[$alias] !== $prevData[$alias])) {
if ( ! empty($currData[$alias]) && $driver->isIdentifiable($currData[$alias], $table)) {
if ($alias === $rootAlias) {
// dealing with root component
if ($alias === $rootAlias) { $array[$index] = $driver->getElement($currData[$alias], $componentName);
// dealing with root component $prev[$alias] =& $array[$index];
if ( ! isset($prevData[$alias]) || $currData[$alias] !== $prevData[$alias]) { $index++;
if ( ! empty($currData[$alias])) { } else {
$parent = $cache[$key]['parent'];
$array[$index] = $driver->getElement($currData[$alias], $componentName); $relation = $this->_aliasMap[$cache[$key]['alias']]['relation'];
$prev[$alias] =& $array[$index];
$index++;
}
}
} else {
$parent = $cache[$key]['parent'];
$relation = $this->_aliasMap[$cache[$key]['alias']]['relation'];
if ( ! isset($prevData[$alias]) || $currData[$alias] !== $prevData[$alias]) {
if ( ! empty($currData[$alias])) {
// check the type of the relation // check the type of the relation
if ( ! $relation->isOneToOne()) { if ( ! $relation->isOneToOne()) {
@ -892,30 +863,25 @@ class Doctrine_Hydrate implements Serializable
} }
foreach ($currData as $alias => $data) { foreach ($currData as $alias => $data) {
$componentName = $this->_aliasMap[$alias]['table']->getComponentName(); $componentName = $this->_aliasMap[$alias]['table']->getComponentName();
if ($alias === $rootAlias) { if ( ! isset($prevData[$alias]) || (isset($currData[$alias]) && $currData[$alias] !== $prevData[$alias])) {
// dealing with root component if ( ! empty($currData[$alias]) && $driver->isIdentifiable($currData[$alias], $table)) {
if ( ! isset($prevData[$alias]) || $currData[$alias] !== $prevData[$alias]) {
if ( ! empty($currData[$alias])) {
if ($alias === $rootAlias) {
// dealing with root component
$array[$index] = $driver->getElement($currData[$alias], $componentName); $array[$index] = $driver->getElement($currData[$alias], $componentName);
$prev[$alias] =& $array[$index]; $prev[$alias] =& $array[$index];
$index++; $index++;
}
}
} else {
$parent = $this->_aliasMap[$alias]['parent'];
$relation = $this->_aliasMap[$alias]['relation'];
$componentAlias = $relation->getAlias();
if ( ! isset($prevData[$alias]) || $currData[$alias] !== $prevData[$alias]) {
// check the type of the relation
if ( ! $relation->isOneToOne()) {
$prev[$parent][$component][] = $driver->getElement($currData[$alias], $componentName);
$driver->registerCollection($prev[$parent][$component]);
} else { } else {
$prev[$parent][$component] = $driver->getElement($currData[$alias], $componentName); $parent = $this->_aliasMap[$alias]['parent'];
$relation = $this->_aliasMap[$alias]['relation'];
$componentAlias = $relation->getAlias();
// check the type of the relation
if ( ! $relation->isOneToOne()) {
$prev[$parent][$component][] = $driver->getElement($currData[$alias], $componentName);
$driver->registerCollection($prev[$parent][$component]);
} else {
$prev[$parent][$component] = $driver->getElement($currData[$alias], $componentName);
}
} }
} }
} }