lithium\data\collection\RecordSet::_mapRecord()
Converts a PDO Result
array to a nested Record
object.
Builds an associative array with data from the row, with joined row data nested under the relationships name. Joined row data is added and new results consumed from the result cursor under the relationships name until the value of the main primary key changes.
The built array is then hydrated and returned.
Note: Joined records must appear sequentially, when non-sequential records are detected an exception is thrown.
Parameters
-
array
$row
2 dimensional PDO
Result
array
Returns
\lithium\data\entity\RecordReturns a Record
object.
Source
protected function _mapRecord($row) {
$main = array_intersect_key($row, $this->_keyIndex);
if ($main) {
if (in_array($main, $this->_seen)) {
$message = 'Associated records hydrated out of order: ';
$message .= var_export($this->_seen, true);
throw new RuntimeException($message);
}
$this->_seen[] = $main;
}
$i = 0;
$record = [];
do {
$offset = 0;
foreach ($this->_columns as $name => $fields) {
$record[$i][$name] = array_combine(
$fields, array_slice($row, $offset, ($count = count($fields)))
);
$offset += $count;
}
$i++;
if (!$peek = $this->_result->peek()) {
break;
}
if ($main !== array_intersect_key($peek, $this->_keyIndex)) {
break;
}
} while ($main && ($row = $this->_result->next()));
return $this->_hydrateRecord($this->_dependencies, $this->_model, $record, 0, $i, '');
}