public function db()
{
if ($this->db === null) {
$class = get_class($this);
if (!isset(self::$cache[$class]['entity'])) {
$this->_parseClassDocComment();
}
$service = self::$cache[$class]['entity']->table->service;
//Validates service
if (!in_array($service, array('adodb', 'cadb'))) {
throw new ModelException(sprintf("Service %s is not allowed", $service));
}
$this->db = \Scalr::getContainer()->{$service};
}
return $this->db;
}