IcingaObject: set related properties by name

This commit is contained in:
Thomas Gelf 2015-12-03 14:18:19 +01:00
parent 40e154ca37
commit bc449feeef
1 changed files with 23 additions and 0 deletions

View File

@ -34,6 +34,11 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
/* key/value!! */
protected $booleans = array();
// Property suffixed with _id must exist
protected $relations = array(
// property => PropertyClass
);
private $vars;
private $groups;
@ -51,6 +56,16 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
return array_key_exists($property, $this->booleans);
}
public function hasRelation($property)
{
return array_key_exists($property, $this->relations);
}
protected function getRelationClass($property)
{
return __NAMESPACE__ . '\\' . $this->relations[$property];
}
public function supportsCustomVars()
{
return $this->supportsCustomVars;
@ -150,6 +165,14 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
}
}
if ($this->hasRelation($key)) {
$class = $this->getRelationClass($key);
$object = $class::load($value, $this->connection);
if (in_array($object->object_type, array('object', 'external_object'))) {
return parent::set($key . '_id', $object->id);
}
}
return parent::set($key, $value);
}