diff --git a/library/Director/Objects/IcingaObject.php b/library/Director/Objects/IcingaObject.php index 067ea92a..19ab826a 100644 --- a/library/Director/Objects/IcingaObject.php +++ b/library/Director/Objects/IcingaObject.php @@ -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 *