core-bundle/src/Resources/contao/library/Contao/Model/Collection.php
public static function createFromDbResult(Result $objResult, $strTable)
	{
		$arrModels = array();
		$strClass = Model::getClassFromTable($strTable);

		while ($objResult->next())
		{
			/** @var Model $strClass */
			$objModel = Registry::getInstance()->fetch($strTable, $objResult->{$strClass::getPk()});

			if ($objModel !== null)
			{
				$objModel->mergeRow($objResult->row());
				$arrModels[] = $objModel;
			}
			else
			{
				$arrModels[] = new $strClass($objResult);
			}
		}

		return new static($arrModels, $strTable);
	}
public static function createFromDbResult(Result $objResult, $strTable)
	{
		$arrModels = array();
		$strClass = Model::getClassFromTable($strTable);

		while ($objResult->next())
		{
			/** @var Model $strClass */
			$objModel = Registry::getInstance()->fetch($strTable, $objResult->{$strClass::getPk()});

			if ($objModel !== null)
			{
				$objModel->mergeRow($objResult->row());
				$arrModels[] = $objModel;
			}
			else
			{
				$arrModels[] = new $strClass($objResult);
			}
		}

		return new static($arrModels, $strTable);
	}
Create a new collection from a database result

@param Result $objResult The database result object
@param string $strTable  The table name

@return static The model collection