예제 #1
0
 public function testSetterCrashes()
 {
     $db = AetherORM::init($this->config);
     $isOk = false;
     try {
         $db->foo = 'bar';
     } catch (Exception $e) {
         $isOk = true;
     }
     $this->assertTrue($isOk);
 }
예제 #2
0
 public function testTable()
 {
     AetherORM::$_config = $this->config;
     $scheme = new AetherORMScheme('foo', $this->schemeResult);
     $resource = $scheme->getObject();
     $db = 'd';
     $tbl = 'foo';
     $table = new AetherORMTable($resource, $db, $tbl);
     // Forced count, fails because loaded without configinfo
     $cnt = $table->count();
     $this->assertGreaterThan(1, $cnt);
 }
예제 #3
0
 /**
  * Fetch database instance
  *
  * @return boolean
  */
 private function getDb()
 {
     if ($this->_orm === null) {
         try {
             $this->_orm = AetherORM::init();
             $this->_db = $this->_orm->{$this->_database}->getDriver();
         } catch (AetherORMMissingConfigException $e) {
             return false;
         } catch (Exception $e) {
             throw $e;
         }
     }
     return true;
 }
예제 #4
0
 public function testSet()
 {
     $orm = AetherORM::init();
     $foos = $orm['d']->Foo("id >= 1");
     $this->assertTrue(count($foos) > 1);
 }
예제 #5
0
 /**
  * Init method as this is a singleton
  *
  * @return AetherORM
  * @param string $configFile
  */
 public static function init($configFile = false)
 {
     if ($configFile == false) {
         if (AetherORM::$_config !== false) {
             $configFile = AetherORM::$_config;
         } else {
             throw new AetherORMMissingConfigException("No config file specified");
         }
     }
     if (self::$_self == null) {
         self::$_self = new AetherORM($configFile);
     }
     return self::$_self;
 }
예제 #6
0
파일: ORM.php 프로젝트: voldern/aether-orm
 /**
  * Return an array of all the primary keys of the related table.
  *
  * @param string $table table name
  * @param object $model AetherORM model to find relations of
  * @return array
  */
 protected function loadRelations($table, AetherORM $model)
 {
     // Save the current query chain (otherwise the next call will clash)
     $this->db->push();
     $query = $this->db->select($model->foreignKey(NULL) . ' AS id')->from($table)->where($this->foreignKey(NULL, $table), $this->object[$this->primaryKey])->get()->result(true);
     $this->db->pop();
     $relations = array();
     foreach ($query as $row) {
         $relations[] = $row->id;
     }
     return $relations;
 }