From 18c0ce3c4f0a8563ec4af3631f85b6c2a3506eb3 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Wed, 17 May 2017 10:04:50 +0200 Subject: [PATCH] IcingaObject: allow to prefetch related object... ...types --- library/Director/Objects/IcingaObject.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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 *