Contao\Model\Collection::createFromDbResult PHP Method

createFromDbResult() public static method

Create a new collection from a database result
public static createFromDbResult ( Result $objResult, string $strTable ) : static
$objResult Contao\Database\Result The database result object
$strTable string The table name
return static The model collection
    public static function createFromDbResult(Result $objResult, $strTable)
    {
        $arrModels = array();
        $strClass = \Model::getClassFromTable($strTable);
        while ($objResult->next()) {
            /** @var Model $strClass */
            $objModel = \Model\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);
    }