lithium\data\collection\RecordSet::_hydrateRecord()

protected method

Hydrates a 2 dimensional PDO row Result array recursively.

Parameters

  • array $relations

    The cascading with relation

  • string $primary

    Model classname

  • array $record

    Loaded Records

  • integer $min
  • integer $max
  • string $name

    Alias name

Returns

\lithium\data\entity\Record

Returns a Record object as created by the model.

Source

	protected function _hydrateRecord(array $relations, $primary, array $record, $min, $max, $name) {
		$options = ['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 ?: [], $relModel, $record, $min, $max, $relName
				);
				continue;
			}

			$rel = [];
			$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 ?: [], $relModel, $record, $i, $j, $relName
					);
					$main = $keys;
					$i = $j;
				}
				$j++;
			}
			if (array_filter($record[$i][$relName])) {
				$rel[] = $this->_hydrateRecord(
					$subrelations ?: [], $relModel, $record, $i, $j, $relName
				);
			}
			$record[$min][$name][$relField] = $relModel::create($rel, [
				'class' => 'set'
			] + $options);
		}
		return $primary::create(
			isset($record[$min][$name]) ? $record[$min][$name] : [], $options
		);
	}