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
		);
	}