lithium\data\collection\RecordSet::_hydrateRecord PHP Method

_hydrateRecord() protected method

Hydrates a 2 dimensional PDO row Result array recursively.
protected _hydrateRecord ( array $relations, string $primary, array $record, integer $min, integer $max, string $name ) : Record
$relations array The cascading with relation
$primary string Model classname
$record array Loaded Records
$min integer
$max integer
$name string Alias name
return lithium\data\entity\Record Returns a `Record` object as created by the model.
    protected function _hydrateRecord(array $relations, $primary, array $record, $min, $max, $name)
    {
        $options = array('exists' => true, 'defaults' => false);
        foreach ($relations as $relation => $subrelations) {
            $relName = $name ? "{$name}.{$relation}" : $relation;
            $relModel = $this->_relationships[$relName]['model'];
            $relField = $this->_relationships[$relName]['fieldName'];
            $relType = $this->_relationships[$relName]['type'];
            if ($relType !== 'hasMany') {
                $record[$min][$name][$relField] = $this->_hydrateRecord($subrelations ?: array(), $relModel, $record, $min, $max, $relName);
                continue;
            }
            $rel = array();
            $main = $relModel::key($record[$min][$relName]);
            $i = $min;
            $j = $i + 1;
            while ($j < $max) {
                $keys = $relModel::key($record[$j][$relName]);
                if ($main != $keys) {
                    $rel[] = $this->_hydrateRecord($subrelations ?: array(), $relModel, $record, $i, $j, $relName);
                    $main = $keys;
                    $i = $j;
                }
                $j++;
            }
            if (array_filter($record[$i][$relName])) {
                $rel[] = $this->_hydrateRecord($subrelations ?: array(), $relModel, $record, $i, $j, $relName);
            }
            $record[$min][$name][$relField] = $relModel::create($rel, array('class' => 'set') + $options);
        }
        return $primary::create(isset($record[$min][$name]) ? $record[$min][$name] : array(), $options);
    }