diff --git a/includes/qcodo/_core/codegen/templates/db_orm/class_gen/qcodo_query_methods.tpl b/includes/qcodo/_core/codegen/templates/db_orm/class_gen/qcodo_query_methods.tpl index 1fe92916..a092ff77 100644 --- a/includes/qcodo/_core/codegen/templates/db_orm/class_gen/qcodo_query_methods.tpl +++ b/includes/qcodo/_core/codegen/templates/db_orm/class_gen/qcodo_query_methods.tpl @@ -82,9 +82,31 @@ throw $objExc; } - // Perform the Query, Get the First Row, and Instantiate a new <%= $objTable->ClassName %> object + // Perform the Query $objDbResult = $objQueryBuilder->Database->Query($strQuery); - return <%= $objTable->ClassName %>::InstantiateDbRow($objDbResult->GetNextRow(), null, null, null, $objQueryBuilder->ColumnAliasArray); + + // Instantiate a new <%= $objTable->ClassName %> object and return it + + // Do we have to expand anything? + if ($objQueryBuilder->ExpandAsArrayNodes) { + $objToReturn = array(); + while ($objDbRow = $objDbResult->GetNextRow()) { + $objItem = <%= $objTable->ClassName %>::InstantiateDbRow($objDbRow, null, $objQueryBuilder->ExpandAsArrayNodes, $objToReturn, $objQueryBuilder->ColumnAliasArray); + if ($objItem) $objToReturn[] = $objItem; + } + + if (count($objToReturn)) { + // Since we only want the object to return, lets return the object and not the array. + return $objToReturn[0]; + } else { + return null; + } + } else { + // No expands just return the first row + $objDbRow = $objDbResult->GetNextRow(); + if (is_null($objDbRow)) return null; + return <%= $objTable->ClassName %>::InstantiateDbRow($objDbRow, null, null, null, $objQueryBuilder->ColumnAliasArray); + } } /**