Commit 5de6c0a6 authored by zYne's avatar zYne

Simplified object population mechanism

parent ca213ac6
......@@ -273,112 +273,82 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
if($this->aggregate)
return $stmt->fetchAll(PDO::FETCH_ASSOC);
switch(count($this->tables)):
case 0:
throw new Doctrine_Exception("No tables selected");
break;
case 1:
$keys = array_keys($this->tables);
$name = $this->tables[$keys[0]]->getComponentName();
if(count($this->tables) == 0)
throw new Doctrine_Exception("No tables selected");
while($data = $stmt->fetch(PDO::FETCH_ASSOC)):
$keys = array_keys($this->tables);
$root = $keys[0];
foreach($data as $key => $value):
$e = explode("__",$key);
if(count($e) > 1) {
$previd = array();
$data[end($e)] = $value;
} else {
$data[$e[0]] = $value;
}
unset($data[$key]);
endforeach;
$this->data[$name][] = $data;
endwhile;
$coll = $this->getCollection($root);
$prev[$root] = $coll;
return $this->getCollection($keys[0]);
break;
default:
if($this->aggregate)
$return = Doctrine::FETCH_ARRAY;
$keys = array_keys($this->tables);
$root = $keys[0];
$array = $this->parseData($stmt);
$previd = array();
$coll = $this->getCollection($root);
$prev[$root] = $coll;
if($this->aggregate)
$return = Doctrine::FETCH_ARRAY;
$array = $this->parseData($stmt);
if($return == Doctrine::FETCH_ARRAY)
return $array;
if($return == Doctrine::FETCH_ARRAY)
return $array;
foreach($array as $data) {
/**
* remove duplicated data rows and map data into objects
*/
foreach($data as $key => $row) {
if(empty($row))
continue;
foreach($array as $data) {
/**
* remove duplicated data rows and map data into objects
*/
foreach($data as $key => $row) {
if(empty($row))
continue;
$ids = $this->tables[$key]->getIdentifier();
$name = $key;
$ids = $this->tables[$key]->getIdentifier();
$name = $key;
if($this->isIdentifiable($row, $ids)) {
if($this->isIdentifiable($row, $ids)) {
$prev = $this->initRelated($prev, $name);
continue;
}
$prev = $this->initRelated($prev, $name);
continue;
}
if( ! isset($previd[$name]))
if( ! isset($previd[$name]))
$previd[$name] = array();
if($previd[$name] !== $row) {
// set internal data
$this->tables[$name]->setData($row);
if($previd[$name] !== $row) {
// set internal data
// initialize a new record
$record = $this->tables[$name]->getRecord();
$this->tables[$name]->setData($row);
// initialize a new record
$record = $this->tables[$name]->getRecord();
if($name == $root) {
// add record into root collection
$coll->add($record);
unset($previd);
if($name == $root) {
} else {
$prev = $this->addRelated($prev, $name, $record);
}
// add record into root collection
$coll->add($record);
unset($previd);
// following statement is needed to ensure that mappings
// are being done properly when the result set doesn't
// contain the rows in 'right order'
if($prev[$name] !== $record)
$prev[$name] = $record;
}
$previd[$name] = $row;
} else {
$prev = $this->addRelated($prev, $name, $record);
}
// following statement is needed to ensure that mappings
// are being done properly when the result set doesn't
// contain the rows in 'right order'
if($prev[$name] !== $record)
$prev[$name] = $record;
}
return $coll;
endswitch;
$previd[$name] = $row;
}
}
return $coll;
}
/**
* initRelation
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment