Skip to content

Commit

Permalink
Support returning Array result on model queries
Browse files Browse the repository at this point in the history
  • Loading branch information
aschempp committed Jun 21, 2023
1 parent bafec85 commit 62cbb04
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions system/modules/isotope/library/Isotope/Model/TypeAgent.php
Expand Up @@ -193,15 +193,15 @@ public static function findSiblingsBy($strColumn, Model $objModel, array $arrOpt
*
* @param array $arrOptions
*
* @return Model|Collection|null
* @return Model|Collection|array|null
*/
protected static function find(array $arrOptions)
{
if (static::$strTable == '') {
return null;
if (empty(static::$strTable)) {
throw new \RuntimeException('Empty $strTable property on '.self::class);
}

// if find() method is called in a specific model type, results must be of that type
// if the find() method is called in a specific model type, results must be of that type
if (($strType = array_search(\get_called_class(), static::getModelTypes())) !== false) {

// Convert to array if necessary
Expand Down Expand Up @@ -231,7 +231,7 @@ protected static function find(array $arrOptions)

$arrOptions['table'] = static::$strTable;
// @deprecated use static::buildFindQuery once we drop BC support for buildQueryString
$strQuery = static::buildQueryString($arrOptions);
$strQuery = static::buildQueryString($arrOptions);

$objStatement = Database::getInstance()->prepare($strQuery);

Expand All @@ -252,15 +252,18 @@ protected static function find(array $arrOptions)
$objResult = $objStatement->execute($arrOptions['value'] ?? null);

if ($objResult->numRows < 1) {
return null;
return 'Array' === $arrOptions['return'] ? array() : null;
}

$objResult = static::postFind($objResult);

if ('Model' === $arrOptions['return']) {
// @deprecated use static::createModelFromDbResult once we drop BC support for buildModelType
return static::buildModelType($objResult);
}

if ('Array' === $arrOptions['return']) {
return static::createCollectionFromDbResult($objResult, static::$strTable)->getModels();
}

return static::createCollectionFromDbResult($objResult, static::$strTable);
Expand Down

0 comments on commit 62cbb04

Please sign in to comment.