• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/lib/orm/query/result.php
  • Класс: BitrixMainORMQueryResult
  • Вызов: Result::initializeFetchObject
protected function initializeFetchObject($asCollection = false)
{
	if (empty($this->objectInitPassed))
	{
		// validate query
		if (!empty($this->query->getGroupChains()))
		{
			throw new SystemException(
				'Result of query with aggregation could not be fetched as an object'
			);
		}

		// initialize
		if (empty($this->identityMap))
		{
			// identity map could have been set before first fetch
			$this->identityMap = new IdentityMap;
		}

		$this->objectClass = $this->query->getEntity()->getObjectClass();

		$this->buildSelectChainsMap();
		$this->definePrimaryAliases();

		// values will be cast anyway based on original fields, not just associated with column types
		//$this->setStrictValueConverters();

		$this->objectInitPassed = true;

		// if there are back references, fetch everything and make virtual ArrayResult
		if (!$asCollection && $this->query->hasBackReference())
		{
			/** @var Collection $collection */
			$collection = $this->fetchCollection();

			// remember original result
			$originalResult = $this->result;

			$this->result = new ArrayResult($collection->getAll());

			// recover count total
			try
			{
				if ($originalResult->getCount())
				{
					$this->result->setCount($originalResult->getCount());
				}
			}
			catch (BitrixMainObjectPropertyException $e) {}
		}
	}
}