IcingaObject: allow to prefetch related object...

...types
This commit is contained in:
Thomas Gelf 2017-05-17 10:04:50 +02:00
parent 875627ead7
commit 18c0ce3c4f
1 changed files with 19 additions and 0 deletions

View File

@ -318,6 +318,25 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
return null;
}
public function prefetchAllRelatedTypes()
{
foreach (array_unique(array_values($this->relations)) as $relClass) {
/** @var static $class */
$class = __NAMESPACE__ . '\\' . $relClass;
$class::prefetchAll($this->getConnection());
}
}
public static function prefetchAllRelationsByType($type, Db $db)
{
/** @var static $class */
$class = self::classByType($type);
/** @var static $dummy */
$dummy = $class::create(array(), $db);
$dummy->prefetchAllRelatedTypes();
}
/**
* Whether this Object supports custom variables
*